在Android中,可以四给不同层次上开启硬件加速:

1、Application

android:hardwareAccelerated="true">

2、Activity

android:hardwareAccelerated="true">

3、Window

getWindow().setFlags(WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,

WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);

4、View

view.setLayerType(View.LAYER_TYPE_SOFTWARE,

null);

在这四个层次中,应用和Activity是可以选择的,Window只能打开,View只能关闭。

在apk的AndroidManifest中,如果指定了minSDKVersion&targetSDKVersion=7,会使得应用无法使用硬件加速进行绘图。

注:有些朋友可能会遇到在开发过程中用到虚线的情况,实现有两种方式:

方式一:

hundsun_include_dotted_line.xml


encoding="utf-8"?>

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

style="@style/HundsunStyleWmHw"

android:background="@drawable/hundsun_shape_dotted_line" />

hundsun_shape_dotted_line.xml


encoding="utf-8"?>

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

android:shape="line" >


android:dashGap="@dimen/hundsun_dimen_wee_spacing"

android:dashWidth="@dimen/hundsun_dimen_small_spacing"

android:width="@dimen/hundsun_dimen_normal_divide"

android:color="@color/hundsun_app_color_divide" />


这种方式需要在使用该虚线的Activity中设置,缺点是这个Activity会变慢,如果有网络请求时,大概率出现收到数据后不会回调问题(断点时,每次都会回调,这是很多人遇到的奇怪问题)。

方式二(建议使用这种方式):

hundsun_include_dash_line.xml


encoding="utf-8"?>

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

android:layout_width="match_parent"

android:layout_height="@dimen/hundsun_dimen_normal_divide"

android:background="@drawable/hundsun_shape_dash" />

hundsun_shape_dash.xml


encoding="utf-8"?>

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

android:src="@drawable/hundsun_dashed_line"

android:tileMode="repeat" />

hundsun_dashed_line.png是一张图片,只要很小很小就行,自动平铺的。另外对APP进行在线全方位的安全性、兼容性测试,我都会用这个:www.ineice.com。

更多相关文章

  1. Android 日历方式显示的日期选择组件
  2. Android四种点击事件和五中存储方式
  3. android 定时请求(两种实现方式)
  4. android使用Animation的两种方式
  5. Android设置Activity全屏的三种方式
  6. android代理联网,wap方式联网
  7. android打开数据连接(目测最稳定方式)
  8. android 使用Http的POST方式读取网络数据
  9. Android学习(十) SQLite 基于SQLiteOpenHelper的操作方式

随机推荐

  1. 自学系列 | 就谈知识体系!
  2. Python异步爬虫进阶必备,效率杠杠的!
  3. Ansible 之 外部变量文件调用
  4. JavaScript的工作原理:引擎、运行时和调用
  5. 图解「剑指Offer」之二维数组中的查找
  6. 超简单的博弈算法题,一行代码解决!
  7. 超经典MySQL练习50题,做完这些你的SQL就过
  8. 三分钟理解字符串经典考题:有效的字母异位
  9. 动画:面试必刷之二叉树中和为某一值的路径
  10. 使用位运算处理一道难题:获取所有钥匙的最