android shape定義虛線不顯示 問題 簡單解決

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" />

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章