您的位置:首页 > 移动开发 > Android开发

【Android 开发】Android中自定义ListView中Item间的分割线

2017-03-12 15:57 471 查看
============================================================================================================================================================================================================================================================================相信大家在做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。=======================================================================================
 <ListViewandroid: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"/>
1234567812345678list_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"/>
1234512345colors.xml
<?xml version="1.0" encoding="utf-8"?><resources><color name="colorPrimary">#63a219</color></resources>
======================================================================================自定义虚线的listView分割线 ==========================================================================================================================================
<ListViewandroid: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"/>
1234567891012345678910list_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 --><strokeandroid:width="1dp"android:color="#63a219"android:dashGap="3dp"android:dashWidth="6dp"/><!-- 虚线的高度 --><size android:height="5dp"/></shape>
1234567891011121312345678910111213如果虚线加载不出来,在 AndroidManifest.xml文件中,把硬件加速功能关掉就可以了,android:hardwareAccelerated=”false”。 欢迎学习交流,觉得还行就定下咯
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐