Hardware Acceleration——硬件加速

以下来自google:

Beginning in Android 3.0 (API level 11), the Android 2D rendering pipeline supports hardware acceleration, meaning that all drawing operations that are performed on a View's canvas use the GPU. Because of the increased resources required to enable hardware acceleration, your app will consume more RAM.


Hardware acceleration is enabled by default if your Target API level is >=14, but can also be explicitly enabled. If your application uses only standard views and Drawables, turning it on globally should not cause any adverse drawing effects. However, because hardware acceleration is not supported for all of the 2D drawing operations, turning it on might affect some of your custom views or drawing calls. Problems usually manifest themselves as invisible elements, exceptions, or wrongly rendered pixels. To remedy this, Android gives you the option to enable or disable hardware acceleration at multiple levels. See Controlling Hardware Acceleration.

If your application performs custom drawing, test your application on actual hardware devices with hardware acceleration turned on to find any problems. The Unsupported drawing operations section describes known issues with hardware acceleration and how to work around them.


大体意思是android自3.0引入了硬件加速, Android的2D渲染支持硬件加速,即使用GPU进行绘图,旨在得到更加平滑的动画更加平滑滚动,但是会消耗较大的内存,从API 14往上都是默认开启的,但是硬件加速并不能完善的支持所有的绘图,通常表现为内容不可见,异常或渲染错误,如果出现这样的错需要自己去关闭掉。也可以选择在多个级别启用或禁用硬件加速。

我的平台是在一个退出dialog的出现时出现闪花屏抖动现象,在关掉了当前activity的硬件加速之后,就好了。

可以从四个级别层次启用或禁止:

  • Application
  • Activity
  • Window
  • View

1.Application层:


在你的manifest文件中,把以下属性添加到<application>标签来对你的整个应用启用硬加速:
<applicationandroid:icon="@drawable/ic_launcher_settings"android:hardwareAccelerated="true" ...> </application>


这是启用~相关闭置为false就可以了.


2.activity层:

如果你的应用在全局启用硬加速时行为不正确,你可以对个别activities单独启用硬加速.欲在actvity级别启用或禁止硬加速,你可以对<activity>元素使用android:hardwareAccelerated属性.下面的例子在整个应用中启用了硬加速但对一个activity禁止了硬加速:

<application android:hardwareAccelerated="true"><activity android:hardwareAccelerated="false" /></activity></application>


3.Window层:

如果你需要更高颗粒度的控制,你可以使用以下代码为一个window启用硬加速:

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

目前在Window层面还不能禁止加速.

4.View层:

你可以在运行时使用以下代码禁止个别的View的硬加速:

myView.setLayerType(View.LAYER_TYPE_SOFTWARE,null);

当前你不能在View级别启用硬加速.View层有除禁止硬加速之外的其它功能.


5.判定一个View是否能被硬加速:

有两种方法可以检查应用是否被硬加速:

View.isHardwareAccelerated():如果View附加到一个硬加速的window上就返回true.Canvas.isHardwareAccelerated():如果Canvas被硬加速了就返回true.









更多相关文章

  1. android传感器;摇一摇抽签功能
  2. Android传感器开发基本流程
  3. android如何禁止安装第三方应用
  4. android WebView 启用javaScript
  5. 又一处疑难杂症的折腾笔记:Android内嵌html5获取定位信息
  6. Android中的硬件加速
  7. 仿WP8样式的Android(安卓)ProgressBar
  8. Android禁止横屏竖屏切换
  9. EditText禁止输入中文设置

随机推荐

  1. Android中Binder与AIDL之间的关系
  2. ffmpag总结_android_to_ios视频转换
  3. Android app图标application中修改无效解
  4. 未捕获异常的处理
  5. Android保持屏幕常亮的三种方法
  6. ubuntu 编译 Android 出现的若干错误及解
  7. Android sdk content loader 0%的解决方
  8. Android开发常见的问题
  9. 解决:Android Studio添加依赖时出现“Mani
  10. Android五大存储之SharedPreference