使用shape繪制虛線時,在xml布局中顯示的是虛線,在手機上運作起來卻是實線,網上說是android4.0以上預設把Activity的硬體加速打開了,在Manifest.xml中關掉即可
</pre><pre name="code" class="html"><activity ...<span style="font-family: Arial, Helvetica, sans-serif;">android:hardwareAccelerated="false"/></span>
試了之後發現沒效果,最終的解決方案是在view中把layerType設定成software
<View
android:layerType="software"
android:layout_width="match_parent"
android:layout_height="3dp"
android:background="@drawable/dotted_line" />
dotted_line.xml檔案
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line" >
<stroke
android:dashGap="3dp"
android:dashWidth="3dp"
android:width="1dp"
android:color="#2f000000" />
<size android:height="1dp" />
</shape>