美文网首页
Android用shape画虚线不显示问题

Android用shape画虚线不显示问题

作者: pilipalaKing | 来源:发表于2017-11-09 10:05 被阅读0次
<?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="6dp"  
        android:width="1dp"  
        android:color="#63a219" />  
    <!-- 虚线的高度 -->  
    <size android:height="1dp" />  
</shape>  

破折线的宽度为dashWith,破折线之间的空隙宽度为dashGap,当dashGap=0dp时,为实线

从3.0开始,安卓关闭了硬件加速功能。所以4.0以上设备虚线会变实线

1、在 AndroidManifest.xml中把硬件加速的功能关掉就可以了
 android:hardwareAccelerated="false"

2、代码中可以添加:
line.setLayerType(View.LAYER_TYPE_SOFTWARE, null);  

3、xml中可以添加:
android:layerType="software"  

相关文章

网友评论

      本文标题:Android用shape画虚线不显示问题

      本文链接:https://www.haomeiwen.com/subject/bwcpmxtx.html