TtT23
TtT23

Reputation: 7040

How to make first row of tablelayout take whole space

I have a table layout with 5rows. I'd like the size of first row to take the rest of the screen while the remaining rows take as much space they need based on the content inside.

My first intuition was to make the first row's layout width and height set to match_parent while having the other rows' width to match_parent and height to wrap_content. Needless to say, this does not work.

How can I accomplish this?

enter image description here

Upvotes: 2

Views: 628

Answers (4)

sebastian
sebastian

Reputation: 2890

stick to your first intuition but add layout_weight="1" to the first row.`

Upvotes: 0

Matt Taylor
Matt Taylor

Reputation: 3408

Seeing as TableLayout inherits from LinearLayout, have you tried setting Row height to 0dp and setting layout weights for each one to achieve the desired effect? Like so:

<TableRow 
    android:layout_height="0dp"
    android:layout_weight="2"
    android:layout_width="match_parent">

<TableRow 
    android:layout_height="0dp"
    android:layout_weight="1"
    android:layout_width="match_parent">
and so on....

Upvotes: 0

user
user

Reputation: 87074

I'd like the size of first row to take the rest of the screen while the remaining rows take as much space they need based on the content inside.

I think that using android:layout_weight="1" on the first TableRow should solve the problem you have.

Upvotes: 1

TNR
TNR

Reputation: 5869

Put your TableLayout inside a ScrollView and fix the Height of your First TableRow which will solve your issue. Hope it works.

Upvotes: 0

Related Questions