View-Shape虚线

在android中画一条虚线,可以通过shape设置背景
在drawable文件下创建xml文件:
< shape xmlns: android = "http://schemas.android.com/apk/res/android"
android :shape= "line" >
< stroke
android :dashGap= "1dp"
android :dashWidth= "4dp"
android :width= "1dp"
android :color= "#666666" />
</ shape >
width:线的高度
dashWidth:实线宽度
dashGap:虚线宽度

使用过程中的问题: 在4.0以上会设置完后变成实线
解决:
1.代码中设置
view.setLayerType(View. LAYER_TYPE_SOFTWARE , null );
2.xml文件中设置
android :layerType= "software"

猜你喜欢

转载自blog.csdn.net/zmesky/article/details/80393077