我的表格布局如下所示,我使用以下代码设置了行之间的分隔符及其颜色,我可以在我的设计中看到分隔符已设置,但没有设置分隔符颜色!
请告诉我如何设置行之间的分隔线颜色?
用于在表格布局中设置分隔线及其颜色的代码。
android:showDividers="middle"
android:divider="@color/colorAccent"
全表布局代码。
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/table_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:orientation="vertical"
android:showDividers="middle"
android:divider="@color/colorAccent"
tools:context=".BookAppointment"
android:stretchColumns="1">
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/table_row_margin"
android:orientation="horizontal"
android:textAlignment="center">
<ImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_marginLeft="@dimen/margin"
android:padding="@dimen/padding"
android:src="@drawable/india_flag" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="@dimen/margin"
android:textSize="@dimen/cell_text_size" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="@dimen/margin"
app:srcCompat="@drawable/chevron_right_24px"
android:layout_gravity="center_vertical" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/table_row_margin"
android:orientation="horizontal">
<ImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_marginLeft="@dimen/margin"
android:padding="@dimen/padding"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="@dimen/margin"
android:textSize="@dimen/cell_text_size" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="@dimen/margin"
app:srcCompat="@drawable/chevron_right_24px"
android:layout_gravity="center_vertical" />
</TableRow>
</TableLayout>
在你的代码中看不到问题。但这里有一个确切的例子。
对于行之间的分隔符:
<TableLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:divider="@color/colorPrimary"
android:showDividers="middle">
对于列之间的分隔符:
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:divider="@color/colorPrimary"
android:showDividers="middle">
解释:
<TableLayout>
中的分隔符标签用于在其直接子项(即行)之间放置分隔符。
虽然 <TableRow>
中的分隔符标签用于在其直接子级(即列)之间放置分隔符
你可以创建一个可绘制的"cell_divider.xml":
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<color android:color="#f00" />
</item>
</selector>
您可以在分隔符属性中设置可绘制对象,例如:
android:divider="@drawable/cell_divider"
尝试使用可绘制形状作为表格布局的分隔线。
divider_shape.xml
<?xml version="1.0" encoding="UTF-8"?>
<inset xmlns:android="http://schemas.android.com/apk/res/android"
android:insetBottom="2dp"
android:insetTop="2dp">
<shape>
<size android:width="1dp" />
<solid android:color="#FFCCCCCC" />
</shape>
</inset>
并将其添加到您的表格布局中,如下所示
android:divider="@drawable/divider_shape"
android:showDividers="middle"