如何在Android中使用虚线/虚线分隔线创建ListView? [英] How do I create a ListView with dashed / dotted line dividers in Android?
本文介绍了如何在Android中使用虚线/虚线分隔线创建ListView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我设法通过在/app/res/drawable/中创建一个名为 dash.xml 的文件来弄清楚如何创建自定义形状(带有虚线笔划) em>文件夹:
I managed to figure out how to create a custom shape (with a dashed stroke) by creating a file called dash.xml inside of the /app/res/drawable/ folder:
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line">
<stroke
android:color="#534b4b"
android:width="1dp"
android:dashGap="2dp"
android:dashWidth="1dp"
/>
<size
android:height="1dp"
/>
</shape>
现在,我对如何将此形状应用于ListView感到困惑.我已经尝试了以下方法,但是没有显示分隔线:
Now I'm confused as to how to apply this shape to a ListView. I've tried the following, but no divider is displayed:
<ListView android:id="@+id/android:list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:cacheColorHint="#00000000"
android:divider="@drawable/dash"
android:dividerHeight="1dp"
/>
Wtf?
推荐答案
这是我的,并且有效:
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line">
<stroke
android:color="#FF404040"
android:width="1dp"
android:dashGap="3dp"
android:dashWidth="1dp"
/>
<size
android:height="3dp"
/>
</shape>
这篇关于如何在Android中使用虚线/虚线分隔线创建ListView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文