Развернуть последнюю строку TableLayout

У меня есть 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>

person Kris B    schedule 16.02.2012    source источник


Ответы (3)


Просто используйте более простой 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>
person Randy Sugianto 'Yuku'    schedule 16.02.2012

Решение:

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

См. ниже 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:orientation="horizontal" android:id="@+id/title"
    android:background="#FF0000">

    <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>
</RelativeLayout>
person Shreyash Mahajan    schedule 16.02.2012

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

person Vinay    schedule 16.02.2012