Развернуть последнюю строку TableLayout - PullRequest
4 голосов
/ 16 февраля 2012

У меня есть TableLayout с примерно 3 рядами.Я хотел бы получить высоту последней строки, чтобы заполнить оставшуюся часть представления, но мне не повезло (так как работа с макетами Android - бесполезный урок).Это то, что я до сих пор:

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="*" >

     <TableRow android:padding="5dip">
          <TextView
             android:text="Row 1"
          />
     </TableRow>
     <TableRow android:padding="5dip">
         <TextView
            android:text="Row 2"
          />
    </TableRow>
    <TableRow android:padding="5dip" android:layout_height="fill_parent">
        <TextView
             android:text="Row 3"
          />
    </TableRow>
</TableLayout>

Ответы [ 3 ]

3 голосов
/ 16 февраля 2012

Решение:

Для этого вы должны использовать weight в макете.

См. Ниже XML-код:

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    >

    <TableRow android:padding="5dip">
        <TextView android:text="Row 1" />
    </TableRow>
    <TableRow android:padding="5dip">
        <TextView android:text="Row 2" />
    </TableRow>
    <TableRow android:padding="5dip" android:layout_weight="1">
        <TextView android:text="Row 3" />
    </TableRow>
</TableLayout>

Наслаждайтесь. :)

1 голос
/ 16 февраля 2012

Просто используйте более простой LinearLayout. 0dp ниже является преднамеренным.

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

     <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:padding="5dip" android:orientation="horizontal">
          <TextView
             android:text="Row 1"
          />
     </LinearLayout>
     <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:padding="5dip" android:orientation="horizontal">
         <TextView
            android:text="Row 2"
          />
    </LinearLayout>
    <LinearLayout android:layout_width="fill_parent" android:padding="5dip" android:layout_height="0dp" android:layout_weight="1" android:orientation="horizontal">
        <TextView
             android:text="Row 3"
          />
    </LinearLayout>
</LinearLayout>
0 голосов
/ 16 февраля 2012

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

...