我如何製作應用程序以適合使用相對佈局的所有屏幕尺寸? 目前我使用的按鈕位置和尺寸的常數值,它只在HTC One S上看起來很好。這就是我用於開發的設備。 我希望按鈕位於每個顯示屏上的適當位置。如何製作應用以適合使用相對佈局的所有屏幕尺寸?
我在應用一個背景,那就是HUD,你可以看到它在這裏:
按鈕和LED必須在孔內的確切位置。它看起來像這樣:
佈局:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/hud"
android:orientation="horizontal"
android:splitMotionEvents="false"
android:windowEnableSplitTouch="false"
tools:context=".MainActivity" >
<ImageButton
android:id="@+id/connect_button"
android:layout_width="122sp"
android:layout_height="122sp"
android:layout_marginLeft="338dp"
android:layout_marginTop="54dp"
android:background="@drawable/connect_inactive"
android:contentDescription="@string/connect_button_description" />
<ImageButton
android:id="@+id/disconnect_button"
android:layout_width="122sp"
android:layout_height="122sp"
android:layout_marginLeft="338dp"
android:layout_marginTop="195dp"
android:background="@drawable/disconnect_inactive"
android:contentDescription="@string/disconnect_button_description" />
<ImageButton
android:id="@+id/throttleup_button"
android:layout_width="122sp"
android:layout_height="122sp"
android:layout_marginLeft="483dp"
android:layout_marginTop="54dp"
android:background="@drawable/throttleup_inactive"
android:contentDescription="@string/throttleup_button_description" />
<ImageButton
android:id="@+id/throttledown_button"
android:layout_width="122sp"
android:layout_height="122sp"
android:layout_marginLeft="483dp"
android:layout_marginTop="195dp"
android:background="@drawable/throttledown_inactive"
android:contentDescription="@string/throttledown_button_description" />
<ImageButton
android:id="@+id/moveforward_button"
android:layout_width="170sp"
android:layout_height="160sp"
android:layout_marginLeft="79dp"
android:layout_marginTop="30dp"
android:background="@drawable/control_forward_inactive"
android:contentDescription="@string/moveforward_button_description" />
<ImageButton
android:id="@+id/movebackward_button"
android:layout_width="170sp"
android:layout_height="160sp"
android:layout_marginLeft="79dp"
android:layout_marginTop="153dp"
android:background="@drawable/control_backward_inactive"
android:contentDescription="@string/movebackward_button_description" />
<ImageButton
android:id="@+id/moveleft_button"
android:layout_width="170sp"
android:layout_height="160sp"
android:layout_marginLeft="17dp"
android:layout_marginTop="92dp"
android:background="@drawable/control_left_inactive"
android:contentDescription="@string/moveleft_button_description" />
<ImageButton
android:id="@+id/moveright_button"
android:layout_width="170sp"
android:layout_height="160sp"
android:layout_marginLeft="141dp"
android:layout_marginTop="92dp"
android:background="@drawable/control_right_inactive"
android:contentDescription="@string/moveright_button_description" />
<ImageView
android:id="@+id/led"
android:layout_width="45sp"
android:layout_height="45sp"
android:layout_marginLeft="297dp"
android:layout_marginTop="280dp"
android:background="@drawable/led_inactive"
android:contentDescription="@string/led_description" />
</RelativeLayout>