Search code examples
androidandroid-layoutandroid-tablelayout

Expand last row of TableLayout


I have a TableLayout with about 3 rows. I'd like to get the last row's height to fill in the rest of the View, but not having much luck (since working with Android layouts is a lesson in futility). This is what I have so far:

<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>

Solution

  • Just use the easier LinearLayout. 0dp below is intentional.

    <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>