首页 > 移动平台 > 详细

【转】Android Shape绘制虚线在手机端查看是实线的问题

时间:2017-07-29 18:06:41      阅读:419      评论:0      收藏:0      [点我收藏+]

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

原文博客链接: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

 

【转】Android Shape绘制虚线在手机端查看是实线的问题

原文:http://www.cnblogs.com/liyanli-mu640065/p/7256899.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!