Android TableRow RelativeLayout Issue
Asked Answered
F

3

7

I have the following

<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
          android:id="@+id/admin_row"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:gravity="center_horizontal">
    <RelativeLayout android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:orientation="horizontal"
                    android:background="@color/silver">

I dynamically populate the table but with the relative layout colored silver it only spans about 3/4 of the table row. If I put a LinearLayout with horizontal orientation it spans completely but if I change it to vertical the same problem occurs. I need a relative layout in the table row because I need to something like this:

Value
Detail MoreDetail.

Any ideas on getting the relative layout to span the table row?

Fusilier answered 19/1, 2010 at 16:46 Comment(0)
K
11

Try setting android:stretchColumns="0" or else android:stretchColumns="*" on your TableLayout tag.

Kampmann answered 28/4, 2010 at 13:50 Comment(0)
F
6

So I had temporarily moved on from this issue but it came up again. To reiterate, the problem I was seeing was that a relative layout within a table row would not span the entire row no matter what I set it's width and height to. I have found a solution that forces any layout to span the table row entirely (horizontally):

<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
          android:id="@+id/detail_row"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content">
    <RelativeLayout android:layout_height="fill_parent"
                    android:layout_width="0dp"
                    android:layout_weight="1"
                    android:orientation="horizontal">

Note this seems to be in direct contradiction to what the table row java docs state:

The children of a TableRow do not need to specify the layout_width and layout_height attributes in the XML file. TableRow always enforces those values to be respectively FILL_PARENT and WRAP_CONTENT.

Fusilier answered 2/2, 2010 at 17:20 Comment(1)
You just made my day and help me meet my deadline. Thanks a bunch!Fritzie
L
1

You should put the android:background="@color/silver" attribute on the TableRow.

I had the same issue with a LinearLayout inside a ScrollView.

Hope it helps,

Lint

Lonna answered 19/1, 2010 at 20:37 Comment(1)
I am not trying to color the row. I was using it as a debug mechanism to determine why my relative layout will not span the entire row.Fusilier

© 2022 - 2024 — McMap. All rights reserved.