Android Shape绘制虚线

在Drawable中定义文件

<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"  android:shape="line" >  <stroke  android:dashGap="2dp"  android:dashWidth="4dp"  android:width="1dp"  android:color="#999999" />  <!-- 虚线的高度 -->  <size android:height="1dp" /> </shape>

引用

<View  android:layerType="software"  android:layout_marginTop="5dp"  android:layout_below="@+id/layout_top"  android:id="@+id/divider"  android:background="@drawable/dash_line"  android:layout_width="match_parent"  android:layout_height="2dp"/>

Tips:View的高度要大于虚线的高度才能显示,一定要加上 android:layerType="software" ,不然的话你会发现手机上显示的时候成实线了。

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容