Подтвердить что ты не робот

Как сделать линейное заполнение оставшегося пространства в режиме релятивирования?

У меня есть relativelayout с тремя linearlayouts как дети. Последний имеет фиксированную высоту и имеет android: layout_alignParentBottom установлен на "true". В то время как средний расположен правильно ниже первого, он доходит до нижней части экрана, так что его нижняя часть перекрывается третьим.

Что не так?

Спасибо

<?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/category"
        android:layout_width="fill_parent"
        android:layout_height="50dp"
        android:layout_alignParentTop="true"
        android:orientation="horizontal" >

        <ImageView
            android:id="@+id/back_btn"
            android:layout_width="29dp"
            android:layout_height="34dp"
            android:layout_gravity="center_vertical"
            android:src="@drawable/red_arrow_left" />

        <TextView
            android:id="@+id/cat_name"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:gravity="center"
            android:textSize="20sp" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_below="@+id/category"
        android:layout_marginTop="10dp"
        android:orientation="horizontal" >

        <ListView
            android:id="@+id/android:list"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:background="@android:color/white"
            android:cacheColorHint="@android:color/white" />

        <TextView
            android:id="@+id/android:empty"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:background="@android:color/white"
            android:cacheColorHint="@android:color/white"
            android:padding="10dp"
            android:text="@string/no_item" />
    </LinearLayout>

    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/nav_bar"
        android:layout_width="fill_parent"
        android:layout_height="40dp"
        android:layout_alignParentBottom="true"
        android:orientation="horizontal" >
    //stuff

    </LinearLayout>
</RelativeLayout>
4b9b3361

Ответ 1

Нееет... решение намного проще! Вы забыли сказать, что хотели, чтобы второй линейный макет был выше третьего :) Да, второй линейный макет должен иметь ОБА android:layout_below="@+id/category" и android:layout_above="@+id/nav_bar". Я проверил это, и это работает.

Но, конечно, вы можете использовать вес для достижения тех же результатов, это будет сложнее...

Вот ваш XML с упомянутыми мною изменениями (проверено в eclipse):

<?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/category"
        android:layout_width="fill_parent"
        android:layout_height="50dp"
        android:layout_alignParentTop="true"
        android:orientation="horizontal" >

        <ImageView
            android:id="@+id/back_btn"
            android:layout_width="29dp"
            android:layout_height="34dp"
            android:layout_gravity="center_vertical"
            android:src="@drawable/red_arrow_left" />

        <TextView
            android:id="@+id/cat_name"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:gravity="center"
            android:textSize="20sp" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_above="@+id/nav_bar"
        android:layout_below="@+id/category"
        android:layout_marginTop="10dp"
        android:orientation="horizontal" >

        <ListView
            android:id="@+id/android:list"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:background="@android:color/white"
            android:cacheColorHint="@android:color/white" />

        <TextView
            android:id="@+id/android:empty"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:background="@android:color/white"
            android:cacheColorHint="@android:color/white"
            android:padding="10dp"
            android:text="@string/no_item" />
    </LinearLayout>

    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/nav_bar"
        android:layout_width="fill_parent"
        android:layout_height="40dp"
        android:layout_alignParentBottom="true"
        android:orientation="horizontal" >
//stuff

    </LinearLayout>
</RelativeLayout>

Ответ 2

Вы можете попробовать использовать весы для управления относительными размерами дочерних макетов. В моем блоге есть статья

RelativeLayout был заменен на LinearLayout, все относительные теги позиционирования были удалены, а в центр LinearLayout добавлен атрибут layout_weight, который заставит его растягиваться, чтобы заполнить доступное пространство.

Ответ 3

Вы должны добавить идентификатор для вашего второго LinearLayout

    <LinearLayout 
        android:orientation="horizontal"
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent"        
        android:layout_below="@+id/category" 
        android:layout_marginTop="10dp"
        android:id="@+id/YOUR_ID">

и в третьем макете добавьте android:layout_below="@id/YOUR_ID"

   <LinearLayout 
       android:id="@+id/nav_bar"
       android:layout_below="@id/YOUR_ID"
       android:orientation="horizontal" 
       android:layout_width="fill_parent"        
       android:layout_height="40dp" 
       android:layout_alignParentBottom="true">