============================================================================================================================================================================================================================================================================
相信大家在做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。
=======================================================================================
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
list_item_divider.xml
- 1
- 2
- 3
- 4
- 5
- 1
- 2
- 3
- 4
- 5
colors.xml
======================================================================================
自定义虚线的listView分割线==========================================================================================================================================
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
list_item_dash.xml
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
如果虚线加载不出来,在 AndroidManifest.xml文件中,把硬件加速功能关掉就可以了,android:hardwareAccelerated=”false”。
欢迎学习交流,觉得还行就定下咯