Android通过代码实现虚线或者虚线框shape

来源:互联网 发布:变老软件 编辑:程序博客网 时间:2024/06/05 20:47

虚线

<?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="#f3f3f3"        android:dashWidth="3dp"        android:dashGap="3dp" /></shape>

虚线框

<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android"    android:shape="rectangle">    <stroke        android:width="1dp"        android:color="#f3f3f3"        android:dashWidth="3dp"        android:dashGap="3dp" /></shape>

虚线圆

<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android"    android:shape="oval">    <stroke        android:width="1dp"        android:color="#f3f3f3"        android:dashWidth="3dp"        android:dashGap="3dp" /></shape>

顶部虚线

<?xml version="1.0" encoding="utf-8"?><layer-list xmlns:android="http://schemas.android.com/apk/res/android">    <item        android:left="-2dp"        android:right="-2dp"        android:bottom="-2dp">        <shape>            <stroke                android:width="1dp"                android:color="#f3f3f3"                android:dashWidth="3dp"                android:dashGap="3dp" />        </shape>    </item></layer-list>

底部虚线

<?xml version="1.0" encoding="utf-8"?><layer-list xmlns:android="http://schemas.android.com/apk/res/android">    <item        android:left="-2dp"        android:right="-2dp"        android:top="-2dp">        <shape>            <stroke                android:width="1dp"                android:color="#f3f3f3"                android:dashWidth="3dp"                android:dashGap="3dp" />        </shape>    </item></layer-list>

使用

android:background="@drawable/shape_dash_line"