详细:http://developer.android.com/intl/zh-cn/guide/topics/graphics/hardware-accel.html
Application level
In your Android manifest file, add the following attribute to the <application>
tag to enable hardware acceleration for your entire application:
<application android:hardwareAccelerated="true" ...>
Activity level
If your application does not behave properly with hardware acceleration turned on globally, you can control it for individual activities as well. To enable or disable hardware acceleration at the activity level, you can use theandroid:hardwareAccelerated
attribute for the <activity>
element. The following example enables hardware acceleration for the entire application but disables it for one activity:
<application android:hardwareAccelerated="true"> <activity ... /> <activity android:hardwareAccelerated="false" /> </application>
Window level
If you need even more fine-grained control, you can enable hardware acceleration for a given window with the following code:
getWindow().setFlags( WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED, WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
Note: You currently cannot disable hardware acceleration at the window level.
View level
You can disable hardware acceleration for an individual view at runtime with the following code:
myView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
Note: You currently cannot enable hardware acceleration at the view level. View layers have other functions besides disabling hardware acceleration. See View layers for more information about their uses.
Determining if a View is Hardware Accelerated
It is sometimes useful for an application to know whether it is currently hardware accelerated, especially for things such as custom views. This is particularly useful if your application does a lot of custom drawing and not all operations are properly supported by the new rendering pipeline.
There are two different ways to check whether the application is hardware accelerated:
View.isHardwareAccelerated()
returnstrue
if theView
is attached to a hardware accelerated window.Canvas.isHardwareAccelerated()
returnstrue
if theCanvas
is hardware accelerated
If you must do this check in your drawing code, use Canvas.isHardwareAccelerated()
instead ofView.isHardwareAccelerated()
when possible. When a view is attached to a hardware accelerated window, it can still be drawn using a non-hardware accelerated Canvas. This happens, for instance, when drawing a view into a bitmap for caching purposes.