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层:
<application android:icon="@drawable/ic_launcher_settings" android:hardwareAccelerated="true" ...> </application>
2.activity层:
<application android:hardwareAccelerated="true"> <activity android:hardwareAccelerated="false" /> </activity> </application>
3.Window层:
getWindow().setFlags( WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED, WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
目前在Window层面还不能禁止加速.
4.View层:
myView.setLayerType(View.LAYER_TYPE_SOFTWARE,null);
当前你不能在View级别启用硬加速.View层有除禁止硬加速之外的其它功能.
5.判定一个View是否能被硬加速:
View.isHardwareAccelerated():如果View附加到一个硬加速的window上就返回true. Canvas.isHardwareAccelerated():如果Canvas被硬加速了就返回true.