Android TableRow RelativeLayout Issue
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. 开发者_JAVA百科Any ideas on getting the relative layout to span the table row?
Try setting android:stretchColumns="0" or else android:stretchColumns="*" on your TableLayout tag.
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.
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
精彩评论