shape画竖的虚线

记录一下

方案来源于:骑马倚斜桥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,不然显示不出来。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容