RelativeLayout с закрепленной сверху и снизу? - PullRequest
2 голосов
/ 02 ноября 2011

Я пытаюсь создать экран Android с привязкой TableLayout к вершине, затем прокруткой для заполнения середины и TableLayout с привязкой к нижней части.Я использовал RelativeLayout с alignParentTop / alignParentBottom, и отображается нижний TableLayout, но верхний исчезает.

Можно ли закрепить отдельные секции наверху и внизу с прокручиваемой областью, заполняющей середину?Представьте панель кнопок сверху и снизу с прокручиваемыми элементами посередине.Вот мой макет, который был близок, но не совсем работает.Я также пытался использовать TableLayout и 3 строки, в средней из которых было установлено fill_parent и ScrollView, но не смог заставить это работать.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/LinearLayout01"
  android:orientation="vertical"
  android:layout_width="match_parent"
  android:layout_height="match_parent">
  <TableLayout
       android:id="@+id/CategoryTable01"
        android:stretchColumns="*"
        android:background="#000000"
        android:layout_height="80px"
        android:layout_alignParentTop="true"
        android:layout_width="fill_parent">
        <TableRow 
            android:id="@+id/tr01"
            android:layout_height="fill_parent"
            android:layout_width="wrap_content"
            android:padding="10px"
            android:layout_gravity="center_vertical|center_horizontal">
            <TextView android:text="TOP1" android:textColor="#0000FF" android:layout_height="fill_parent" android:layout_gravity="fill_vertical" android:textStyle="bold" />
            <TextView android:text="TOP2" android:textColor="#CCCCCC" android:layout_height="fill_parent" android:layout_gravity="fill_vertical" android:textStyle="bold" />
        </TableRow>
   </TableLayout>
<ScrollView android:id="@+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/LinearLayout02"
  android:orientation="vertical"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">
    <TableLayout
        android:id="@+id/TableLayout01"
        android:stretchColumns="*"
        android:background="@drawable/gradient"
        android:layout_height="wrap_content"
        android:paddingLeft="20px"
        android:layout_width="fill_parent">
        <TableRow
            android:id="@+id/TableRow01"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:layout_gravity="center_vertical|center_horizontal">
            <TextView android:textColor="#FFFFFF"
                android:textStyle="bold"
                android:textSize="12dip"
                android:text="Sample Line 1"></TextView>
        </TableRow>
        <TableRow
            android:id="@+id/TableRow02"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:layout_gravity="center_vertical|center_horizontal">
            <TextView android:textColor="#FFFFFF"
                android:textSize="11dip"
                android:text="Sample Line 2"></TextView>
        </TableRow>
        <TableRow
            android:id="@+id/TableRow03"
            android:layout_height="600px"
            android:layout_width="wrap_content"
            android:layout_gravity="center_vertical|center_horizontal">
            <TextView android:textColor="#FFFF00"
                android:textSize="11dip"
                android:text="Sample Line 3"></TextView>
        </TableRow>
    </TableLayout>
    </LinearLayout>
    </ScrollView>
  <TableLayout
       android:id="@+id/CategoryTable02"
        android:stretchColumns="*"
        android:background="#000000"
        android:layout_height="80px"
        android:layout_alignParentBottom="true"
        android:layout_width="fill_parent">
        <TableRow 
            android:id="@+id/tr02"
            android:layout_height="fill_parent"
            android:layout_width="wrap_content"
            android:padding="10px"
            android:layout_gravity="center_vertical|center_horizontal">
            <TextView android:text="ONE" android:textColor="#0000FF" android:layout_height="fill_parent" android:layout_gravity="fill_vertical" android:textStyle="bold" />
            <TextView android:text="TWO" android:textColor="#CCCCCC" android:layout_height="fill_parent" android:layout_gravity="fill_vertical" android:textStyle="bold" />
            <TextView android:text="THREE" android:textColor="#CCCCCC" android:layout_height="fill_parent" android:layout_gravity="fill_vertical" android:textStyle="bold" />
            <TextView android:text="FOUR" android:textColor="#CCCCCC" android:layout_height="fill_parent" android:layout_gravity="fill_vertical" android:textStyle="bold" />
        </TableRow>
   </TableLayout>
</RelativeLayout>

Спасибо за любые предложения или помощь.

Michael

1 Ответ

5 голосов
/ 03 ноября 2011

Это действительно возможно.Вот как у меня это работает в одном из моих приложений (я вырезал кучу ненужных вещей, таких как идентификаторы):

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <!--this is the action bar at the top of the screen)-->
    <fragment
            android:layout_width="match_parent"
            android:layout_height="40dip" />

    <!-- This is the list view in the middle -->
    <ListView 
        android:layout_width="match_parent"
        android:layout_weight="1"
        android:layout_height="0dip">
    </ListView>

    <!-- This is a bunch of buttons at the bottom -->
    <RelativeLayout 
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="5dip"
        android:gravity="bottom">
    </RelativeLayout>

</LinearLayout>

Ключ в том, чтобы установить ваш средний просмотр списка на высоту 0dip идавайте возьмем layout_weight - layout_weight примерно сравним с шириной / высотой в процентах в HTML - если у вас есть 4 различных элемента с весом 0,25, каждый из них будет занимать четверть экрана.Таким образом, вес 1,0 занимает все, что может.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...