shape畫豎的虛線

記錄一下

方案來源于:騎馬倚斜橋w的簡書文章

shape 能畫實線、虛線,都是橫線。要變成豎線,需要旋轉(zhuǎn)。
注意:如果是實線豎線,不用 shape 實現(xiàn)更快。

<?xml version="1.0" encoding="utf-8"?>

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

    <item
        android:left="-300dp"
        android:right="-300dp">
        <rotate
            android:fromDegrees="90"
            android:visible="true">
            <shape android:shape="line">
                <stroke
                    android:width="1dp"
                    android:color="@color/sale_stage_complete_color"
                    android:dashGap="2dp"
                    android:dashWidth="6dp"/>
            </shape>
        </rotate>
    </item>
</layer-list>
 <View
        android:id="@+id/viewLine"
        android:layout_width="0.5dp"
        android:layout_height="80dp"
        android:layerType="software"
        android:background="@drawable/shape_sale_stage_select_line"/>

1、dashwidth是指- - -中每一個-的寬度,dashGap是指- - -中每一個間隔的寬度,如果dashwidth和dashGap中有一個為0,那么這條線就是一條實線。width是指這條線的寬度,在橫的虛線上體現(xiàn)出來就是這條線的豎直方向的高度。

2、把這個drawable作為一個view的背景時,需要設(shè)置view的layerType為software,不然在真機上顯示出來是一條實線。

3、作為背景的view的layout_height要超過drawble的stroke的width,不然顯示不出來。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容