Android 具有相同列的两个TableLayout
我的表格布局中的列宽有问题。在这种情况下,我有多个需要对齐的TableLayout,问题是它们位于不同的XML文件中,同一个文件多次膨胀,每个文件都有一个TableLayout 这是XMLAndroid 具有相同列的两个TableLayout,android,tablelayout,Android,Tablelayout,我的表格布局中的列宽有问题。在这种情况下,我有多个需要对齐的TableLayout,问题是它们位于不同的XML文件中,同一个文件多次膨胀,每个文件都有一个TableLayout 这是XML <?xml version="1.0" encoding="utf-8"?> <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_pare
<?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>
这是我想要它的样子
我希望有人能在这方面帮助我。需要知道的重要一点是,每一行TableLayout都在它自己的XML中,我无法将TableLayout放在这些XML之外。如果表只有两列,那么使用线性布局和为线性布局的每个成员指定布局权重可能会更容易。以下是一个例子:
<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>
您只需确保各个视图的布局权重之和等于父视图组的权重之和