[英]How to make my layout fit in all screens
我在庫存溢出和鏈接方面經歷了許多相對答案,例如支持不同的屏幕或屏幕兼容模式
我創建了以下相對布局,並試圖使它在所有android屏幕中看起來都一樣。
我的圖像非常適合4.8英寸手機,但是當我嘗試使用2.8英寸顯示器或類似的東西時,某些按鈕會疊在其他按鈕上,並且不會縮水。
有沒有人建議如何改進它?
並且最好不要增加我的應用程序的大小。
提前致謝!
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:mm="http://millennialmedia.com/android/schema"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/background"
tools:context=".MainActivity" >
<ImageButton
android:id="@+id/Switch_off"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:onClick="someMethod"
android:background="@drawable/switch_off"/>
<ImageView
android:id="@+id/warning_shot"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="@drawable/more"
android:onClick="someMethod" />
<ImageView
android:id="@+id/imageViewBatteryState"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="@+id/Switch_off"
/>
<ImageView
android:id="@+id/sh"
android:layout_width="147dp"
android:layout_height="54dp"
android:layout_below="@+id/Switch_off"
android:layout_centerHorizontal="true"
android:background="@drawable/me"/>
<ImageView
android:id="@+id/sit"
android:layout_width="100dp"
android:layout_height="50dp"
android:layout_below="@+id/Switch_off"
android:layout_centerHorizontal="true"
/>
<TextView
android:id="@+id/textViewBatteryInfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#ffffff"
android:textSize="12sp"
android:textStyle="bold"
android:typeface="monospace"
android:layout_alignBottom="@+id/sit"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
我建議您專門針對此問題使用LinearLayout而不是Relativelayout:
我的圖像非常適合4.8英寸手機,但是當我嘗試使用2.8英寸顯示器或類似的東西時,某些按鈕會疊在其他按鈕上,並且不會縮水。
因為當您為Linearlayout設置方向時 ,其子級將永遠不會在任何分辨率或屏幕尺寸上相互重疊。
而且,如果您賦予它們權重,則每個設備的視圖都將處於固定位置。
例如,將Xml下面放在您的項目中,然后以“任何分辨率”將其簽出,它將得到相同的結果。
XML:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:mm="http://millennialmedia.com/android/schema"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
tools:context=".MainActivity" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="@+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button 1" />
<Button
android:id="@+id/button2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button 2" />
<Button
android:id="@+id/button3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button 3" />
</LinearLayout>
</LinearLayout>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.