Android繪制虛線有很多種方式,常用的就是通過drawable資源繪制虛線。示例代碼如下:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="line">
<stroke android:width="1dip" android:dashWidth="2dip" android:dashGap="4dip" android:color="@color/white" />
</shape>
android:shape="line" 定義圖片形狀是線條
android:width="1dip" 定義線條寬度
android:dashWidth="2dip" 虛線長度
android:dashGap="4dip" 間隙大小
android:color="@color/white" 線條顏色
在使用的過程中,常常發(fā)現(xiàn)預(yù)覽的時(shí)候可以看到虛線,但是實(shí)際運(yùn)行后卻看不到虛線了,通過下面代碼可以解決問題:
<View
android:layerType="software"
/>
其實(shí)就是關(guān)閉視圖硬加速就可以了。