Android虚线绘制潜在ICS错误
以下是一条虚线,在XML中定义为ShapeDrawable:Android虚线绘制潜在ICS错误,android,xml-drawable,shapedrawable,Android,Xml Drawable,Shapedrawable,以下是一条虚线,在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=
<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>
这将在几个姜饼手机上画一条漂亮的虚线。然而,在Galaxy Nexus上,虚线似乎被忽略,形状被绘制为一条连续的线。更奇怪的是,运行ICS的仿真器会用破折号正确地呈现它,这只是物理设备出了问题
我错过了什么明显的东西吗?或者这真的是安卓4.0的一个bug?这条线在好几个地方使用。以下是一个示例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" />
在此处记录此问题,关闭硬件加速将显示虚线。在处记录的问题有一条注释,说明将以下内容应用于您的视图:
view.setLayerType(View.LAYER_TYPE_SOFTWARE, null)
这对我很有效。我在Galaxy Nexus上的应用程序上也注意到了同样的问题。在我的其他设备2.x设备上,它显示为虚线。注意,如果您不想以编程方式编辑视图,还可以将属性
android:layerType=“software”
添加到XML definition.API 11+中。您是否会将android:layerType=“software”
设置为ImageView
或shape
?我会在ImageView上执行此操作不幸的是,这会使我的性能下降约500%。有什么办法可以防止这种情况吗?不要关闭硬件加速CardView
将丢失其阴影:。