記錄一下
方案來源于:騎馬倚斜橋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,不然顯示不出來。