美文网首页
shape画竖的虚线

shape画竖的虚线

作者: 一缕阳忆往昔 | 来源:发表于2017-09-06 17:40 被阅读0次

记录一下

方案来源于:骑马倚斜桥w的简书文章

shape 能画实线、虚线,都是横线。要变成竖线,需要旋转。
注意:如果是实线竖线,不用 shape 实现更快。

<?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是指这条线的宽度,在横的虚线上体现出来就是这条线的竖直方向的高度。

2、把这个drawable作为一个view的背景时,需要设置view的layerType为software,不然在真机上显示出来是一条实线。

3、作为背景的view的layout_height要超过drawble的stroke的width,不然显示不出来。

相关文章

网友评论

      本文标题:shape画竖的虚线

      本文链接:https://www.haomeiwen.com/subject/euevjxtx.html