由于我这简单,所以使用 ListView 而不是RecycleView。
ListView的分割线代码:
<com.zhy.autolayout.AutoLinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<com.wumart.pos.aaatest.MyListView
android:id="@+id/my_list_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="@drawable/monitor_list_item_dash_main"
android:dividerHeight="@dimen/px_2" />
</com.zhy.autolayout.AutoLinearLayout>
monitor_list_item_dash_main:
<?xml version="1.0" encoding="utf-8"?>
<inset xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/monitor_list_item_dash"
android:insetLeft="5dp"
android:insetRight="5dp" />
monitor_list_item_dash:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line">
<stroke
android:width="1dp"
android:color="#fcf9f9"
android:dashGap="2dp"
android:dashWidth="1dp" />
</shape>
-------------------------------华丽的分割线--------------------------------
android中的shape的绘制线条,直接绘制只能是横线,那么要绘制竖线需要将横线旋转90度才能实现竖线的效果
竖直方向虚线:
<TextView />
<ImageView
android:layerType="software"
android:layout_width="@dimen/px_2"
android:layout_height="match_parent"
android:background="@drawable/monitor_list_item_dash_vertical"/>
<TextView />
monitor_list_item_dash_vertical:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:left="-300dp"
android:right="-300dp">
<rotate
android:fromDegrees="90"
android:visible="true">
<shape android:shape="line">
<stroke
android:width="1dp"
android:color="#fcf9f9"
android:dashGap="2dp"
android:dashWidth="1dp" />
</shape>
</rotate>
</item>
</layer-list>
PS: ListView底部分割线不显示的解决办法:小技巧
listView.addHeaderView(new View(this));
listView.addFooterView(new View(this));
原理: android:footerDividersEnabled = true.