android开发日常总结

Androidz中Drawable绘制虚线

2019-06-13  本文已影响1人  aitality

Android绘制虚线有很多种方式,常用的就是通过drawable资源绘制虚线。示例代码如下:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="line">
    <stroke android:width="1dip" android:dashWidth="2dip" android:dashGap="4dip" android:color="@color/white" />
</shape>

android:shape="line" 定义图片形状是线条
android:width="1dip" 定义线条宽度
android:dashWidth="2dip" 虚线长度
android:dashGap="4dip" 间隙大小
android:color="@color/white" 线条颜色

在使用的过程中,常常发现预览的时候可以看到虚线,但是实际运行后却看不到虚线了,通过下面代码可以解决问题:

<View
    android:layerType="software"
   />

其实就是关闭视图硬加速就可以了。

上一篇 下一篇

猜你喜欢

热点阅读