пусть прокрутка заполняет весь экран, за исключением высоты относительной компоновки внизу экрана

Я застрял в том, как заполнить весь экран верхним макетом, за исключением места, необходимого для нижнего макета. Я использую относительные макеты для размещения макетов по мере необходимости, но я хочу, чтобы мой вид сверху занимал все пространство, кроме пространства, необходимого для моего нижнего вида (высота верхнего вида будет меняться в зависимости от ввода пользователя). См. xml ниже. Прямо сейчас мой вид сверху будет занимать столько места, сколько нужно linearlayout внутри прокрутки + пространство, которое занимает myTopButton. XML:

<?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"
        android:background="@drawable/bg"
        android:paddingBottom="10dip"
        android:focusable="true"
        android:focusableInTouchMode="true">
   <RelativeLayout android:id="@+id/topLayout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="80dip"
        android:layout_alignParentTop="true">
     <ScrollView android:id="@+id/myscroll"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_marginBottom="65dip"
        android:paddingRight="2dip"
        android:paddingLeft="6dip"
        android:fillViewport="true">
        <LinearLayout style="@style/LinearLayoutInner"
        android:orientation="vertical">
        </LinearLayout> 
    </ScrollView>
    <LinearLayout android:orientation="horizontal"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_alignParentBottom="true">
            <Button android:id="@+id/search"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
                android:layout_marginBottom="10dip"
                android:text="@string/search_viewdoses"/>
    </LinearLayout>
   </RelativeLayout>
   <RelativeLayout android:id="@+id/bottomLayout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_marginTop="-60dip"
        android:layout_alignParentBottom="true">
            <TextView android:id="@+id/myText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true"
            android:text="@string/mytext"></TextView>
            <EditText android:id="@+id/myEdit" 
                android:layout_width="80dip"
                android:layout_height="50dip"
            android:layout_alignParentBottom="true"
            android:layout_toRightOf="@+id/myText"
            android:singleLine="true"
            android:inputType="numberDecimal"></EditText>
            <Button android:id="@+id/save"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentRight="true"
            android:layout_marginBottom="10dip"
                android:text="@string/mybuttontext"/>
    </RelativeLayout>
</RelativeLayout>

НА ЭКРАНЕ СЕЙЧАС: введите здесь описание изображения

ТРЕБУЕТСЯ ЭКРАН: введите здесь описание изображения


person Agnes    schedule 17.06.2012    source источник
comment
Вы можете установить флаг android:fillViewport для ScrollView, чтобы заставить его не переносить высоту на его содержимое - попробуйте.   -  person MH.    schedule 17.06.2012
comment
Боюсь, я уже установил для android:fillViewport значение true.   -  person Agnes    schedule 18.06.2012
comment
Извините, я совсем забыл об этом! Я заметил, что вы устанавливаете нижнее поле для ScrollView (android:layout_marginBottom="65dip") — разве это не вызывает синий разрыв между красным и зеленым макетами?   -  person MH.    schedule 18.06.2012


Ответы (3)


Просто удалите нижнее поле с topLayout и добавьте к нему android:layout_above="@+d/bottomLayout". Однако вы должны определить bottomLayout перед topLayout в своем xml. Я думаю, вам также следует удалить верхнее поле из вашего bottomLayout.

То же самое касается фактического scrollView и кнопки.

person Maria Neumayer    schedule 17.06.2012
comment
Хм, теперь кнопка scrollview + занимает весь экран!?! - person Agnes; 18.06.2012

Попробуйте поставить android:layout_weight="1" в ScrollView.

person VanessaBR    schedule 17.06.2012

В теге макета

   <RelativeLayout android:id="@+id/topLayout"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="80dip"
    android:layout_alignParentTop="true">

просто удалите android:layout_marginBottom="80dip", и вы должны быть готовы к работе. Это тот, который создает это уродливое, нежелательное пространство внизу вашей верхней части.

person keithmaxx    schedule 07.10.2013