1. 子控件需要在添加分割线则在其父容易中定义divider
android:showDividers="middle"
2. showDividers 可选的参数有 :
beginning | 只在开始的的位置 |
end | 只在结束的位置 |
middle | 每一个子控件中间 |
none | 无分割线 |
3. 设置divider样式,无法单纯设置divider颜色来显示他,还需要(图片、drawable)设置divider的样式:
shape_main_hbf.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#00ffff" />
<size android:height="1dp" />
</shape>
4. 父容器设置
android:showDividers="middle"
android:divider="@drawable/shape_main_hbf"
5. 完成
layout_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:showDividers="middle"
android:divider="@drawable/shape_main_hbf"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="horizontal"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="0dip"/>
<LinearLayout
android:orientation="horizontal"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="0dip"/>
<LinearLayout
android:orientation="horizontal"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="0dip"/>
<LinearLayout
android:orientation="horizontal"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="0dip"/>
</LinearLayout>
shape_main.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#00ffff" />
<size android:height="1dp" />
</shape>

版权声明:本文为qq_36118959原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。