您的位置:首页 > 其它

画一条虚线

2017-12-04 15:20 232 查看
先创建 dashed.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/gainsboro"
android:dashGap="6dp"
android:dashWidth="4dp" />

<size android:height="1dp"/>
</shape>


再将 dashed.xml 作为 View 的背景
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="@drawable/dashed"
android:layerType="software"/>

注意:

1. View 的 height 要比虚线的高度大一点,否则显示不出来;

2. Android 4.0以上设备要设置 layerType 属性为 software ,否则显示的效果是一条实线。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: