表格布局如何与布局宽度相等?
How tablelayout can equal with layout width?
我想让应用程序可以显示来自 RecyclerView 的数据,但它显示的列大小不同。我怎样才能使 tablelayout 等于布局的列大小,因为我对此一无所知?
这是我的代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
>
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="9"
>
<TableRow
android:layout_height="wrap_content"
android:layout_width="0dp"
android:weightSum="9"
android:gravity="left"
android:background="@drawable/borderc">
<TextView
android:id="@+id/namabar"
android:layout_weight="2.5"
android:text="Nama Barang"
android:layout_height="wrap_content"
android:maxLength="15"
android:gravity="left"
android:layout_width="match_parent"
android:background="@drawable/borderc"
/>
<TextView
android:layout_weight="2"
android:id="@+id/jumlahbar"
android:text="Jumlah"
android:layout_height="wrap_content"
android:background="@drawable/borderc"
android:layout_width="match_parent"/>
<TextView
android:layout_weight="2"
android:id="@+id/hargabar"
android:layout_height="match_parent"
android:background="@drawable/borderc"
android:text="Harga"
android:gravity="left"
android:layout_width="match_parent"/>
<TextView
android:id="@+id/kodebar"
android:layout_weight="2.5"
android:background="@drawable/borderc"
android:text="kode"
android:gravity="left"
android:layout_height="wrap_content"
android:layout_width="match_parent"/>
</TableRow>
</TableLayout>
</LinearLayout>
每个 TextView 应该具有相同的权重 =1
每个 TextView 的布局宽度应为 0dp
去除权重总和
先从 TableLayout
和 TableRow
中删除 android:weightSum="9"
。现在在 TableLayout
中添加 android:stretchColumns="*"
。
我想让应用程序可以显示来自 RecyclerView 的数据,但它显示的列大小不同。我怎样才能使 tablelayout 等于布局的列大小,因为我对此一无所知?
这是我的代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
>
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="9"
>
<TableRow
android:layout_height="wrap_content"
android:layout_width="0dp"
android:weightSum="9"
android:gravity="left"
android:background="@drawable/borderc">
<TextView
android:id="@+id/namabar"
android:layout_weight="2.5"
android:text="Nama Barang"
android:layout_height="wrap_content"
android:maxLength="15"
android:gravity="left"
android:layout_width="match_parent"
android:background="@drawable/borderc"
/>
<TextView
android:layout_weight="2"
android:id="@+id/jumlahbar"
android:text="Jumlah"
android:layout_height="wrap_content"
android:background="@drawable/borderc"
android:layout_width="match_parent"/>
<TextView
android:layout_weight="2"
android:id="@+id/hargabar"
android:layout_height="match_parent"
android:background="@drawable/borderc"
android:text="Harga"
android:gravity="left"
android:layout_width="match_parent"/>
<TextView
android:id="@+id/kodebar"
android:layout_weight="2.5"
android:background="@drawable/borderc"
android:text="kode"
android:gravity="left"
android:layout_height="wrap_content"
android:layout_width="match_parent"/>
</TableRow>
</TableLayout>
</LinearLayout>
每个 TextView 应该具有相同的权重 =1
每个 TextView 的布局宽度应为 0dp
去除权重总和
先从 TableLayout
和 TableRow
中删除 android:weightSum="9"
。现在在 TableLayout
中添加 android:stretchColumns="*"
。