相信大家在做ListView时,Item之间需要添加分割线的需求。今天带大家来实现下ListView中在Item间添加分隔线
============================================================================================================================================================================================================================================================================
1.不显示分割线只要在ListView控件中添加android:footerDividersEnabled="false"即可。
<ListView android:id="@+id/local_groups_list" android:layout_width="match_parent" android:layout_height="wrap_content" android:footerDividersEnabled="false" />
2.改变ListView的分割线颜色和宽度,需要在布局中定义android:divider和android:dividerHeight属性。
<ListView android:id="@+id/local_groups_list" android:layout_width="match_parent" android:layout_height="wrap_content" android:divider="@color/divider_color" android:dividerHeight="1px" /> 注明:ListView中每个Item项之间都有分割线,设置Android:footerDividersEnabled表示是否显示分割线,此属性默认为true。
=======================================================================================
<ListView android:id="@+id/list_view" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/white" android:divider="@drawable/list_item_divider" android:dividerHeight="1px" /> 12345678 12345678
list_item_divider.xml
<?xml version="1.0" encoding="utf-8"?> <inset xmlns:android="http://schemas.android.com/apk/res/android" android:drawable="@color/colorPrimary" android:insetLeft="15dp" /> 12345 12345colors.xml
<?xml version="1.0" encoding="utf-8"?> <resources> <color name="colorPrimary">#63a219</color> </resources>======================================================================================
自定义虚线的listView分割线==========================================================================================================================================
<ListView android:id="@+id/list_view" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/white" android:divider="@drawable/list_item_dash" android:dividerHeight="5dp" android:paddingLeft="5px" android:paddingRight="5px" /> 12345678910 12345678910list_item_dash.xml
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="line"> <!-- 显示虚线,破折线的宽度为dashWith,空隙的宽度为dashGap, darkgray --> <stroke android:width="1dp" android:color="#63a219" android:dashGap="3dp" android:dashWidth="6dp"/> <!-- 虚线的高度 --> <size android:height="5dp"/> </shape> 12345678910111213 12345678910111213如果虚线加载不出来,在 AndroidManifest.xml文件中,把硬件加速功能关掉就可以了,android:hardwareAccelerated=”false”。
欢迎学习交流,觉得还行就定下咯