ListView中的底部边线可以通过 divider 属性进行设置, 但是没有提供类似CSS border dashed 的选项, 如果需要设置边线为虚线需要使用 一张图片 和 一个bitmap xml文件.
背景图片:
图片可以使用网页中常用的虚线边框背景图, 类似与CSS中出现的 background repeat-x 类型图片, 一般是一个 1x2px 的透明背景图片. 可以参考这张图片:
Bitmap xml文件:
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/bg_dot_dashed"
android:tileMode="repeat" />
其中 android:src 设置为刚才的那个背景图片.
ListView设置:
<ListView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:divider="@drawable/dashed_line"
android:dividerHeight="1dip"
/>
其中 android:divider 设置为刚才的那个Bitmap xml文件即可.
相关内容
另外附带的说一下如何在任何地方插入一条横线作为分割符, 效果类似与CSS中的 border-bottom: 1px solid #ccc;
<LinearLayout>
android:background="#CCC"
android:layout_width="1px"
android:layout_height="fill_parent"
</LinearLayout>