views:

1247

answers:

3

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?

+1  A: 

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

Lint_
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.
phogel
A: 

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.

phogel
+1  A: 

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

Eric Burke