Reputation: 3578
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>
Upvotes: 4
Views: 1853
Reputation: 23596
Solution:
For that you have to use weight
in layout.
See below XML code:
<?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>
Upvotes: 3
Reputation: 73425
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>
Upvotes: 1
Reputation: 2415
Did you try setting the layout height for other 2 rows or setting it to wrap content and last one as fill parent?
Upvotes: 0