真吊,這個問題搞好好一會。mark一下。
首先 shape_dashed.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="@color/gray_d3d3d3" />
<size android:height="1dp"/>
<!-- 虛線的高度 -->
</shape>
很簡單,不多解釋了,
使用代碼:
<View
android:layerType="software"
android:layout_width="match_parent"
android:layout_height="40px"
android:background="@drawable/shape_dashed" />
解釋一下:
以前用shape做虛線框時,直接設置背景就可以了。
但是,需要顯示一條虛線(不是虛線框)時,卻tm顯示一條實線。
搞不懂。我們要做的就是關閉硬件加速
解決方法:
1.佈局文件的view中添加 android:layerType=”software”
2. AndroidManifest.xml,或者是在activity中把硬件加速的功能關掉就可以了android:hardwareAccelerated=”false”
3. 代碼設置,view.setLayerType(View.LAYER_TYPE_SOFTWARE, null)。
mark!mark!mark!