記錄一下
方案來(lái)源于:騎馬倚斜橋w的簡(jiǎn)書(shū)文章
shape 能畫(huà)實(shí)線、虛線,都是橫線。要變成豎線,需要旋轉(zhuǎn)。
注意:如果是實(shí)線豎線,不用 shape 實(shí)現(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是指- - -中每一個(gè)-的寬度,dashGap是指- - -中每一個(gè)間隔的寬度,如果dashwidth和dashGap中有一個(gè)為0,那么這條線就是一條實(shí)線。width是指這條線的寬度,在橫的虛線上體現(xiàn)出來(lái)就是這條線的豎直方向的高度。
2、把這個(gè)drawable作為一個(gè)view的背景時(shí),需要設(shè)置view的layerType為software,不然在真機(jī)上顯示出來(lái)是一條實(shí)線。
3、作為背景的view的layout_height要超過(guò)drawble的stroke的width,不然顯示不出來(lái)。