#android #xml
#Android #xml
Вопрос:
В XML есть
<Button android:id="@ id/Btn1"
android:layout_height="50dp" android:layout_width="50dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
/>
чтобы расположить элементы наполовину между верхней и нижней частью экрана.
Есть ли также способ position a Button Btn2 right in between Btn1 and the top or buttom
отображения экрана? А затем как расположить кнопку Btn3 right half between Btn1 and Btn2
?
РЕДАКТИРОВАТЬ: мне нужно это в ОТНОСИТЕЛЬНОМ МАКЕТЕ, спасибо
Ответ №1:
Просто примените весь макет, не пропустите ни одной точки снизу. и это будет работать для всех телефонов Android с размером экрана.
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_height="fill_parent" android:id="@ id/linearLayout1" android:layout_width="fill_parent">
<LinearLayout android:id="@ id/linearLayout2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:gravity="center_vertical|center_horizontal">
<Button android:text="Button" android:id="@ id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
</LinearLayout>
<LinearLayout android:layout_height="wrap_content" android:layout_width="fill_parent" android:id="@ id/linearLayout4" android:gravity="center_horizontal">
<Button android:text="Button" android:id="@ id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
</LinearLayout>
<LinearLayout android:id="@ id/linearLayout3" android:layout_height="wrap_content" android:layout_width="fill_parent" android:layout_weight="1" android:gravity="center_vertical|center_horizontal">
<Button android:text="Button" android:id="@ id/button3" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
</LinearLayout>
</LinearLayout>
Комментарии:
1. Спасибо! Как бы я это сделал в относительном макете?
2. относительная компоновка не приведет к тому же результату. попробуйте только это