在Android Lollipop中使用自定义drawable将虚线作为背景(在Nexus 5上)

时间:2014-10-19 16:44:59

标签: android android-layout android-drawable

到目前为止,我使用ImageView(或View,结果相同)在每个项目之间的Custom ListView中绘制一条虚线。 xml布局是这样的:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <!-- Random stuff -->

    <ImageView
       android:layout_width="match_parent"
       android:layout_height="1dp"
       android:src="@drawable/dotted_line" />

</LinearLayout>

我的绘画看起来像:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="line">

    <stroke
        android:dashGap="1dp"
        android:dashWidth="1dp" />

</shape>

我尝试将我的形状包装到选择器中,或者在我的ImageView中添加android:layerType="software",但没有任何效果。我也看到人们建议使ImageView高度更大,或者使用虚线的宽度。我能做到的最好的渲染是绘制一条实线,但不是我想要的虚线。

有人可以帮我绘制这条虚线吗?我应该使用除drawable之外的其他方法吗?谢谢!

0 个答案:

没有答案