Android XML绘图Shape虚线

来源:互联网 发布:黄道日与黑道日的算法 编辑:程序博客网 时间:2024/05/24 06:27

Shape虚线

1、在Drawable上面写Shape的XML文件

<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android"       android:shape="line" >    <stroke //边框        android:width="1dp"        android:color="@color/bg_shop"        android:dashGap="5dp" //虚线间隔        android:dashWidth="5dp" />  //虚线宽度    <!-- 虚线的高度 -->    <size android:height="0.2dp" /></shape>

2、在布局XML设置shape

<View            android:layout_width="match_parent"            android:layout_height="1.5dp"            android:layout_below="@+id/view_head"            android:layout_marginLeft="@dimen/dp_22"            android:layout_marginRight="@dimen/dp_22"            android:layout_marginTop="123.8dp"            android:background="@drawable/line_dotted"            android:layerType="software"/>

这里写图片描述
3、效果图
这里写图片描述

PS:dashGap //虚线间隔,dashWidth //虚线宽度
必须得加上android:layerType=”software”,否则不生效,成直线。

原创粉丝点击