【发布时间】:2016-02-26 07:48:58
【问题描述】:
布局实现
我已经实现了一个 RecyclerView 并为其设置了以下 ListItem。布局实现是我获取输出的方式。
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/partspricinglistheader"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:stretchColumns="*"
android:orientation="vertical">
<TableRow
android:layout_width="0dp"
android:layout_height="40dp"
android:weightSum="6">
<TextView
android:id="@+id/pp_itemno_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Item"
android:textColor="@color/black"
android:textSize="12sp" />
<View
android:layout_width="1dp"
android:layout_height="38dp"
android:background="@color/white" />
<TextView
android:id="@+id/pp_itemdescription_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:layout_weight="1"
android:text="Description"
android:textColor="@color/black"
android:textSize="12sp" />
<View
android:layout_width="1dp"
android:layout_height="38dp"
android:background="@color/white" />
<TextView
android:id="@+id/pp_mrp_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="MRP"
android:textColor="@color/black"
android:textSize="12sp" />
<View
android:layout_width="1dp"
android:layout_height="38dp"
android:background="@color/white" />
<TextView
android:id="@+id/pp_itemquantity_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Set/Quantity"
android:textColor="@color/black"
android:textSize="12sp" />
<View
android:layout_width="1dp"
android:layout_height="38dp"
android:background="@color/white" />
<TextView
android:id="@+id/pp_margincd_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="MARGIN"
android:textColor="@color/black"
android:textSize="12sp" />
<View
android:layout_width="1dp"
android:layout_height="38dp"
android:background="@color/white" />
<TextView
android:id="@+id/pp_itemcat_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="CAT"
android:textColor="@color/black"
android:textSize="12sp" />
</TableRow>
</TableLayout>
我什至使用android:stretchColumns="*" 使用TableLayout,无法按照图片中的要求设置项目行。
【问题讨论】:
-
尝试在您的
TextViews 中将android:layout_width从 "wrap_content" 更改为 "0dp"。 -
改变 android:layout_width 和 android:layout_weight 帮助了我。
标签: android android-layout android-recyclerview android-tablelayout android-layout-weight