Как сделать приложение подходящим для всех размеров экрана с использованием относительной компоновки? В настоящее время я использую постоянные значения для позиций и размеров кнопок, и он выглядит хорошо только на HTC One S. Это устройство, которое я использую для разработки. Я хочу, чтобы кнопки были на соответствующих позициях на каждом дисплее.Как сделать приложение подходящим для всех размеров экрана с использованием относительной компоновки?
У меня есть один фон в приложении, это HUD вы можете увидеть здесь:
Кнопки и индикатор должен находиться в строго определенных местах внутри отверстий. И это выглядит следующим образом:
Расположение:
<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>