下面是一条虚线,在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>
这将在几部姜饼手机上画一条漂亮的虚线。然而,在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" />
在 http://code.google.com/p/android/issues/detail?id=29944 上记录的问题有一个注释,即对您的视图应用以下内容:
view.setLayerType(View.LAYER_TYPE_SOFTWARE, null)
这对我有用。
记录在此处 http://code.google.com/p/android/issues/detail?id=29944 关闭硬件加速将显示虚线。