Android虚线drawable潜在的ICS bug

34

下面是一个虚线,它在XML中被定义为ShapeDrawable:

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

    <size
        android:height="2dp"
        android:width="700dp" />

    <stroke
        android:width="1dp"
        android:color="@android:color/black"
        android:dashWidth="1dp"
        android:dashGap="2dp" />

</shape>

这将在多个Gingerbread手机上绘制一个漂亮的虚线。但在Galaxy Nexus上,破折号似乎被忽略了,并且形状被绘制为连续的线条。更加奇怪的是,运行ICS的模拟器会正确地呈现它们,只有物理设备出现问题。

我是否遗漏了一些明显的东西?还是这真的是Android 4.0的一个错误?这条线在多个地方使用。这是一个ImageView的示例:

<ImageView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="@dimen/observation_observe_side_margin"
    android:layout_marginRight="@dimen/observation_observe_side_margin"
    android:layout_marginTop="16dp"
    android:contentDescription="@string/dotted_line_description"
    android:src="@drawable/dotted_line" />

我在我的Galaxy Nexus应用程序上注意到了同样的问题。在我的其他2.x设备上,它显示为点状。 - Donn Felker
重复的问题。请参考这个链接:http://stackoverflow.com/a/26296229/185022 - AZ_
2个回答

51

35
请注意,如果您不想通过编程方式编辑视图,则还可以在XML定义中添加属性android:layerType="software" - Arkaaito
API 11+ http://developer.android.com/reference/android/view/View.html#setLayerType - Dori
在问题的示例中,你会将 android:layerType="software" 设置到 ImageView 还是 shape - Dave Haigh
2
我会在ImageView上完成它。 - saulpower

25

2
不幸的是,这会使我的性能下降约500%。有什么解决方法可以防止这种情况发生吗? - Philipp Jahoda
请勿关闭硬件加速。 CardView 将失去其阴影:https://dev59.com/OlcQ5IYBdhLWcg3wD_ho. - CoolMind

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接