给布局添加分割线,就像这种,具体做法:
推荐方法:
LinearLayout有两个属性:
1、divider
android:divider = ""
- divider可以是图片文件,也可以是xml绘制的shape。
- 使用shape的时候一定要添加
<size>
,一定要添加color
,即使是透明也要写上
例如:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/black" />
<size android:height="1px" />
</shape>
2、showDividers
android:showDividers = "middle|end|beginning|none"
- middle 在每一项中间添加分割线
- end 在整体的最后一项添加分割线
- beginning 在整体的最上方添加分割线
- none 无
整体的写法就是这样:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:divider="@drawable/divider"
android:showDividers="middle">
</LinearLayout>
文章来源于 https://blog.csdn.net/fengyeNom1/article/details/85244364