
1.Create divider shape(创建shape)
//shape divider_horizontal.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<size android:width="@dimen/divider_width"/>
<solid android:color="@color/colorPrimaryDark"/>
</shape>
2.Add shape to LinearLayout
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="@android:color/white"
android:divider="@drawable/divider_horizontal" //添加分割线
android:dividerPadding="5dp" //设置padding
android:showDividers="middle">//居中显示
<TextView android:layout_width="0dp"
android:layout_weight="0.5"
android:layout_height="wrap_content"
android:gravity="center"
style="@style/Text.Title"
android:text="@string/batman_name"/>
<TextView android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:gravity="center"
style="@style/Text.Title"
android:text="@string/superman_name"/>
</LinearLayout>
上面用到了三个xml属性:
divider -用来定义一个drawable或者color作为分割线
showDividers -指定分割线在哪里显示,它们可以显示在开始位置,中间,末尾或者选择不显示
dividerPadding -给divider添加padding
网友评论