Two TableLayout having the same columns
I have a problem with my column widths in my TableLayouts. This is the situation, I have multiple TableLayouts that need to be aligned all together, the problem is that they are in different XML files (the same one inflated multiple times) and each one has it's one TableLayout.
This is the XML
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:stretchColumns="1">
<TableRow>
<TextView
android:id="@+id/listViewText"
android:layout_width="wrap_content"
android:layout_height="wrap开发者_开发百科_content"
android:layout_gravity="center_vertical" />
<TextView
android:id="@+id/listViewValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical" />
</TableRow>
</TableLayout>
This is an image of how I would like to have it.
I hope that someone can help me with this. Important to know is that every row (TableLayout) is in it's own XML and that I'm not able to place the TableLayout outside these XMLs.
If your table only has two columns its probably easier to use a linear layout and specify the layout_weight
for each member of the LinearLayout. Here is an example:
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weightSum="2">
<TextView android:id="@+id/txt1"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:text="Buy"/>
<TextView android:id="@+id/txt2"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:text="Share"/>
</LinearLayout>
You just need to make sure that the sum of the layout_weight
s of the individual views sums up to the weightSum
of the parent ViewGroup.
精彩评论