Android——Hardware Acceleration

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>标签来对你的整个应用启用硬加速:

<application
android: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.









你可能感兴趣的:(android,view,hardware,花屏,硬件加速)