【问题标题】:Android L is not able to draw dotted line as drawable backgroundAndroid L 无法将虚线绘制为可绘制背景
【发布时间】:2014-07-02 16:40:24
【问题描述】:

Android L 无法将虚线绘制为可绘制背景,如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item> 
<shape  android:shape="line" >

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

    <size android:height="1dp" />

    </shape>
</item>
</selector>

我也在 xml 中使用 layerType='software'。 请帮忙。

【问题讨论】:

  • 你试过添加笔画宽度吗?

标签: xml shape android-5.0-lollipop dotted-line


【解决方案1】:

1. 视图的高度必须至少为 2dp(或wrap_content)才能显示,因为笔划设计为环绕视图而它在 1dp 中没有空间这样做。

2.为您的 xml 添加宽度:

<stroke
    android:width="1dp"
    android:dashGap="1dp"
    android:dashWidth="1dp"
    android:color="#999999" />

<size android:height="1dp" 
    android:width="1dp"/>

3.使用layerType='software'

【讨论】:

  • android:width="1dp" 中风是 android 5.0 及更高版本的必备项
  • 嘿 Itai,您示例中的 size 声明不正确。如果shape 中的stroke 具有1dpwidth,则其size 必须具有至少2dpheight。同样,如果您的shape 中的stroke 具有1dpdashWidth,则其size 必须具有至少width3dp
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-12-27
  • 2016-05-24
  • 2011-04-20
相关资源
最近更新 更多