<?xml version="1.0" encoding="utf-8"?>html
<shape xmlns:android="http://schemas.android.com/apk/res/android" android
android:shape="line">性能
<!-- 顯示一條虛線,破折線的寬度爲dashWith,破折線之間的空隙的寬度爲dashGap,當dashGap=0dp時,爲實線 -->spa
<stroke 3d
android:dashGap="3dp" xml
android:dashWidth="6dp" htm
android:width="1dp" utf-8
android:color="#63a219" /> ci
<!-- 虛線的高度 --> it
<size android:height="2dp" />
</shape>
在background或src中引用,但在android 4.0以上版本中會有BUG,發現無論dashGap設置多大,顯示的都是一條實線。
解決方法:
關閉硬件加速。
能夠在AndroidManifest.xml時的Application標籤加上android:hardwareAccelerated=」false」,這樣整件應用都關閉了硬件加速,虛線能夠正常顯示,可是,關閉硬件加速對性能有些影響,會感受明顯比沒關卡。
也能夠給虛線的view單獨關閉硬件加速:
程序代碼:
line.setLayerType(View.LAYER_TYPE_SOFTWARE,null);
xml:
android:layerType="software"
參考:http://www.pocketdigi.com/20140303/1285.html