<pre name="code" class="java"><?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<rotate
android:fromDegrees="90"
android:toDegrees="90" >
<shape android:shape="line" >
<stroke
android:dashGap="3dp"
android:dashWidth="2dp"
android:width="1dp"
android:color="@color/gray" />
<size
android:height="45dp"
android:width="45dp" />
</shape>
</rotate>
</item>
<item
android:bottom="15dp"
android:drawable="@drawable/icon_todo"
android:left="15.5dp"
android:right="15.5dp"
android:top="15dp">
</item>
</layer-list>
需要实现一个虚线的效果,可是在手机上却显示为是实现。
</pre><pre name="code" class="html">上网找到解决方案:
</pre><pre name="code" class="html">
dashGap是空隙宽度,dashWidth是线的宽度,当dashGap也就是空隙宽度为0时,显示一条实线。然后在background或src中引用,但在android 4.0以上版本中会有BUG,发现不管dashGap设置多大,显示的都是一条实线。
解决办法:
关闭硬件加速。
可以在AndroidManifest.xml时的Application标签加上android:hardwareAccelerated="false",这样整件应用都关闭了硬件加速,虚线可以正常显示,但是,关闭硬件加速对性能有些影响,会感觉明显比没关卡。
也可以给虚线的view单独关闭硬件加速:
view.setLayerType(View.LAYER_TYPE_SOFTWARE, null);