liyyanli

导航

 

Android share绘制虚线在手机上显示实线问题

给控件添加Drawableleft等图片后,单独给图片设置动画效果,参考文章:

http://blog.csdn.net/langzxz/article/details/47069235

效果未测试。

原文博客链接:http://wv1124.iteye.com/blog/2187204

博客分类: 
 

可以说这是一个Bug, 据说在4.0以上机器会出现,我测试是android 4.4.2

Xml代码  收藏代码
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <shape xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:shape="line" >  
  4.   
  5.     <stroke  
  6.         android:dashGap="3dp"  
  7.         android:dashWidth="8dp"  
  8.         android:width="1dp"  
  9.         android:color="#999999" />  
  10.   
  11.     <size android:height="1dp" />  
  12.   
  13. </shape>  

layout中引用:

Xml代码  收藏代码
  1. <View  
  2.         android:layout_width="match_parent"  
  3.         android:layout_height="3dp"  
  4.         android:layout_marginBottom="5dp"  
  5.         android:layout_marginTop="5dp"  
  6.         android:background="@drawable/left_menu_dash_line" />  

 在4.4.2上显示实线。

 

解决:

Xml代码  收藏代码
  1. <View  
  2.         android:layerType="software"  
  3.         android:layout_width="match_parent"  
  4.         android:layout_height="3dp"  
  5.         android:layout_marginBottom="5dp"  
  6.         android:layout_marginTop="5dp"  
  7.         android:background="@drawable/left_menu_dash_line" />  

重点:

Xml代码  收藏代码
  1. android:layerType="software"  

 

 

也可以:

Java代码  收藏代码
  1. <activity android:name=".TestActivity" android:label="Test"  
  2.             android:hardwareAccelerated="false">  

 重点关闭硬件加速:

Java代码  收藏代码
  1. android:hardwareAccelerated="false"  
divider_under_pic.setLayerType(View.LAYER_TYPE_SOFTWARE,null);

 代码中使用setLayerType设置。

 

参考:

http://developer.android.com/guide/topics/graphics/hardware-accel.html

 

posted on 2017-07-29 17:35  liyyanli  阅读(348)  评论(0编辑  收藏  举报