android shape定義虛線不顯示 問題 簡單解決
阿新 • • 發佈:2018-12-27
view 實現虛線,不顯示,搜了一圈,都是說什麼 view 高度要大於 shape 定義的 高度,
現 總結一下 :
這樣寫,關鍵點 :android:width="1dp" 這個代表的才是 shape的 高度,
而 <size android:height="2dp"/> 這個高度屬性 無所謂,刪掉!
android:shape="line" 是 讓繪製出線條,不然是個 容器的背景 四條線 都有
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="line"> <stroke android:width="1dp" android:color="#dedede" android:dashWidth="5dp" android:dashGap="5dp" /> <size android:height="2dp"/> </shape>佈局裡 引用:layout_height 的值 大於 shape 裡邊的 width 就好了 <View android:layout_width="match_parent" android:layout_height="2dp" android:layout_marginLeft="20dp" android:layout_marginTop="5dp" android:layout_marginRight="20dp" android:background="#dedede" android:layerType="software" />