Android 画虚线显示实线的BUG

<?xml version="1.0" encoding="utf-8"?>html

<shape xmlns:android="http://schemas.android.com/apk/res/android" android

     android:shape="line">性能

     <!-- 显示一条虚线,破折线的宽度为dashWith,破折线之间的空隙的宽度为dashGap,当dashGap=0dp时,为实线 -->spa

  <stroke  3d

        android:dashGap="3dp"  xml

        android:dashWidth="6dp"  htm

        android:width="1dp"  utf-8

        android:color="#63a219" />  ci

   

             <!-- 虚线的高度 --> it

     <size android:height="2dp" />    

</shape>

在background或src中引用,但在android 4.0以上版本中会有BUG,发现无论dashGap设置多大,显示的都是一条实线。
解决方法:
关闭硬件加速。
能够在AndroidManifest.xml时的Application标签加上android:hardwareAccelerated=”false”,这样整件应用都关闭了硬件加速,虚线能够正常显示,可是,关闭硬件加速对性能有些影响,会感受明显比没关卡。
也能够给虚线的view单独关闭硬件加速:

程序代码:

line.setLayerType(View.LAYER_TYPE_SOFTWARE,null);

xml:

android:layerType="software" 

参考:http://www.pocketdigi.com/20140303/1285.html

相关文章
相关标签/搜索