Question

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>
Was it helpful?

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>

OTHER TIPS

Solution:

For that you have to use weight in layout.

See below XML code:

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

Enjoy. :)

Did you try setting the layout height for other 2 rows or setting it to wrap content and last one as fill parent?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top