Android-адаптивное расположение кнопок изображения

Я пытаюсь создать дизайн, показанный ниже, но с отзывчивой высотой на кнопках изображения для разных экранов. Хотя я могу получить адаптивную ширину, используя android:layout_weightЯ не могу применить тот же метод к высоте кнопки. Я пытаюсь добиться того, что показано ниже, но с высотой экрана, равномерно распределенной между кнопками. т.е. 25% высоты экрана для каждого ряда кнопок. Любая помощь будет принята с благодарностью!

  <?xml version="1.0" encoding="utf-8"?>
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
   android:layout_height="fill_parent" >

  <LinearLayout
    android:id="@+id/linear1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:orientation="horizontal" >

    <ImageButton
        android:id="@+id/imageButton2"
        android:layout_width="0dp"
        android:layout_weight="0.40"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_pages" />

    <ImageButton
        android:id="@+id/imageButton1"
        android:layout_width="0dp"
        android:layout_weight="0.60"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_pages" />

</LinearLayout>
  <LinearLayout
    android:id="@+id/linear2"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/linear1"
    android:layout_alignParentLeft="true"       
    android:orientation="horizontal" >

    <ImageButton
        android:id="@+id/imageButton3"
        android:layout_width="0dp"
        android:layout_weight="0.60"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_pages" />

</LinearLayout>
  <LinearLayout
    android:id="@+id/linear3"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/linear2"
    android:layout_alignParentLeft="true"       
    android:orientation="horizontal" >

    <ImageButton
        android:id="@+id/imageButton5"
        android:layout_width="0dp"
        android:layout_weight="0.40"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_pages" />

    <ImageButton
        android:id="@+id/imageButton6"
        android:layout_width="0dp"
        android:layout_weight="0.60"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_pages" />

    </LinearLayout>

   <LinearLayout
   android:id="@+id/linear4"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:layout_alignParentLeft="true"
   android:layout_below="@+id/linear3"
   android:orientation="horizontal" >

   <ImageButton
       android:id="@+id/imageButton7"
       android:layout_width="0dp"
       android:layout_height="wrap_content"
       android:layout_weight="0.60"
       android:src="@drawable/ic_pages" />

   <ImageButton
       android:id="@+id/imageButton8"
       android:layout_width="0dp"
       android:layout_height="wrap_content"
       android:layout_weight="0.40"
       android:src="@drawable/ic_pages" />
  </LinearLayout>

</RelativeLayout>

1 ответ

Решение

Обтекание каждого горизонтального LinearLayout в FrameLayout позволило достичь желаемого эффекта.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:orientation="vertical" >
<FrameLayout 
    android:layout_width="match_parent" 
    android:layout_height="0dp"
    android:layout_weight="0.25">

<LinearLayout
    android:id="@+id/linear1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal" >

    <ImageButton
        android:id="@+id/imageButton2"
        android:layout_width="0dp"
        android:layout_weight="0.40"
        android:layout_height="fill_parent"
        android:src="@drawable/ic_pages" />

    <ImageButton
        android:id="@+id/imageButton1"
        android:layout_width="0dp"
        android:layout_weight="0.60"
        android:layout_height="fill_parent"
        android:src="@drawable/ic_pages" />

</LinearLayout>
</FrameLayout>

</LinearLayout>

</RelativeLayout>
Другие вопросы по тегам