- 使用shape绘制虚线时,在xml布局中显示的是虚线,在手机上运行起来却是实线,网上说是android4.0以上默认把Activity的硬件加速打开了,在Manifest.xml中关掉即可
- </pre><pre name="code" class="html"><activity ...<span style="font-family: Arial, Helvetica, sans-serif;">android:hardwareAccelerated="false"/></span>
试了之后发现没效果,最终的解决方案是在view中把layerType设置成software
- <View
- android:layerType="software"
- android:layout_width="match_parent"
- android:layout_height="3dp"
- android:background="@drawable/dotted_line" />
- dotted_line.xml文件
- <?xml version="1.0" encoding="utf-8"?>
- <shape xmlns:android="http://schemas.android.com/apk/res/android"
- android:shape="line" >
- <stroke
- android:dashGap="3dp"
- android:dashWidth="3dp"
- android:width="1dp"
- android:color="#2f000000" />
- <size android:height="1dp" />
- </shape>