android通过shape实现虚线效果

来源:互联网 发布:oracle数据库使用手册 编辑:程序博客网 时间:2024/05/16 12:10

shape资源

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

layout文件设置background即可:

<View    android:layout_width="match_parent"    android:layout_height="2dp"    android:layerType="software"    android:background="@drawable/line_dash" />

有的设备会显示为实线,原因是4.0以上默认把Activity的硬件加速打开了,所以我们在Manifest.xml中关掉Activity的android:hardwareAccelerated="false"
不过不推荐这样实现,还是上面View层实现比较好。因为硬件加速有时候还是必要的!
1 0