Android ListView 设置分割线
ListView中设置分割线一般有两种方法,一种是使用原本的API另一种方法是添加一个View设置宽度很小。
第一种方法:设置android:divider属性
<ListView
Android:id="@+id/android:list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:divider="#CCCCCC
android:dividerHeight="2px"/>
listview去掉横线
方法1:istView.setDividerHeight(0);
方法2:this.getListView().setDivider(null);
方法3:android:divider=”@null”
android:cacheColorHint=”#00000000” 设置其为透明!! 默认为黑色!!!!!
java代码中:
通过ListView的setDivider或setDividerHeight方法:
setDivider的参数是一个Drawable,比如设定列表项之间用一个图像来分隔;setDividerHeight的参数就是高度的数值,单位为像素;
第二种方法添加View:
这里的View既可以添加横线,如果想每一条Item中的空间中间分隔,还可以添加竖直方向的竖线!
竖线
<View
Android:layout_width="1dip"
android:layout_height="match_parent"
android:background="#CCCCFF"
android:layout_gravity="center_horizontal"
/>
横线
<View android:layout_height="1px"
android:layout_width="match_parent"
android:background="#CCCCFF"
/>