Выкладываю экран. Нужна панель инструментов, чтобы остаться на дне - PullRequest
2 голосов
/ 10 мая 2011

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

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

Как мне этого добиться?

Ответы [ 2 ]

7 голосов
/ 10 мая 2011

Как всегда, есть несколько способов.Я бы сделал следующее

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical">
        <ScrollView
            android:layout_width="fill_parent"
            android:layout_height="0dip"
            android:layout_weight="1">
        </ScrollView>
        <LinearLayout
            android:layout_height="wrap_content"
            android:layout_width="fill_parent">
        <Button
            android:text="Button1"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"/>
        <Button
            android:text="Button2"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"/>
        </LinearLayout>
</LinearLayout>

. При этом используется вертикальная линейная компоновка, а кнопки с помощью wrap_content помещаются внизу, а затем ScrollView получает оставшееся пространство, присваивая ему вес «1».

0 голосов
/ 10 мая 2011

Это один из способов сделать это, ключом является android: layout_alignParentBottom = "true" во втором LinearLayout, который здесь содержит две кнопки.

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

    <ScrollView android:layout_width="fill_parent"
        android:layout_height="fill_parent" android:layout_marginTop="5dp"
        android:layout_marginBottom="60dp" android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp">

        <LinearLayout android:orientation="vertical"
            android:layout_width="fill_parent" android:layout_height="wrap_content">

            <TextView android:layout_width="fill_parent"
                android:layout_height="wrap_content" android:text="Some text" />

        </LinearLayout>
    </ScrollView>

    <LinearLayout android:layout_width="fill_parent"
        android:layout_height="wrap_content" android:paddingTop="5dp"
        android:layout_alignParentBottom="true" android:layout_marginTop="5dp">

        <Button android:id="@+id/ok_button" android:layout_width="fill_parent"
            android:layout_weight="1" android:layout_height="wrap_content"
            android:text="OK" android:layout_alignParentLeft="true" />

        <Button android:id="@+id/cancel_button" android:layout_width="fill_parent"
            android:layout_weight="1" android:layout_height="wrap_content"
            android:text="Cancel" android:layout_toRightOf="@id/ok_button" />
    </LinearLayout>
</RelativeLayout>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...