自定义ListView分割线

要完成自定义分割线,我们先来认识一下listview中的两个属性:

  • android:divider 设置list 列表项的分隔条(可用颜色分隔,也可用Drawable分隔)
  • android:dividerHeight 设置分隔线的高度

要完成自定义我们要借助android:divider属性,用drawable自定义样式来实现:如:shape_consult_item.xml

文件内容:

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">   
    <solid android:color="#d6d6d6" //solid设置分隔线线条样式
         android:height="1dip"  />   
    <corners //圆角样式设置
        android:bottomLeftRadius="0dp"
        android:bottomRightRadius="0dp"
        android:topLeftRadius="0dp"
        android:topRightRadius="0dp" />
    <stroke    //stroke设置分隔线填充样式
        android:width="1dip"    
        android:color="#c5c5c5" /> 
</shape>  

那么在ListView中我们就可以这样来用了:

<ListView
    android:id="@+id/finisth_listView"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:divider="@drawable/shape_consult_item"
    android:dividerHeight="13dp" >

看来也挺容易的吗? 世事无难事,只要肯用心,最终都有解。

posted @ 2015-04-01 10:50  fullSunlight  阅读(682)  评论(0编辑  收藏  举报