Android starts with 3.0 (API level 11), supports hardware acceleration when drawing view, takes advantage of GPU features, makes drawing smoother, but consumes more memory.
To turn hardware acceleration on or off:
Because hardware acceleration itself is not perfect, Android offers the option to turn hardware acceleration on or off, which is turned off by default. Hardware acceleration can be turned on or off at 4 levels:
Application level: <applicationandroid:hardwareaccelerated= "true" ...>
Activity level: <activity android:hardwareaccelerated= "false" ...>
Window level:
[Java]View Plaincopy print?
- GetWindow (). SetFlags (Windowmanager.layoutparams.flag_hardware_accelerated,windowmanager.layoutparams.flag_ hardware_accelerated);
Note: Android is not yet supported to turn off hardware acceleration at the window level until now.
View level:
[Java]View Plaincopy print?
- Myview.setlayertype (View.layer_type_hardware, null);
Note: Android also does not support hardware acceleration at the view level so far.
To detect whether hardware acceleration is currently enabled :
[Java]View Plaincopy print?
- // method one
- // this method returns True if MyView hangs under a window with hardware acceleration turned on,
- // that is, it does not necessarily use hardware acceleration when drawing, getdrawingcache
- myview.ishardwareaccelerated ();
-
- // method two
- // returns true if Canvas is drawing with hardware acceleration enabled
- // try to use this method to determine whether hardware acceleration is turned on;
- Canvas.ishardwareaccelerated ();
Method One//This method returns True if MyView hangs under a window with hardware acceleration enabled,//That is, it does not necessarily use hardware acceleration when drawing. Getdrawingcachemyview.ishardwareaccelerated (); Method Two//returns TRUE if the canvas is drawing with hardware acceleration enabled//Try to use this method to determine if hardware acceleration canvas.ishardwareaccelerated () is turned on;
Understanding the drawing model of the View:
1. No hardware acceleration: Invalidate the View hierarchy------> Draw the View hierarchy
2. Hardware acceleration: Invalidate the View hierarchy------> record and update the display list------> draw the Display list
Limitations of hardware acceleration:
Currently, Android support for hardware acceleration is not perfect, and some drawing operations do not work properly when hardware acceleration is turned on (the list can refer to the Android Developer documentation).
However, Android can guarantee that the built-in components and applications support hardware acceleration. Therefore, if you use only standard UI components in your app, you can safely turn on hardware acceleration.
With the Android version upgraded, it is believed that after a while, hardware acceleration can be perfectly supported.
abnormal response after hardware acceleration is turned on:
1. Some UI elements are not displayed: Invalidate may not be called
2. Some UI elements are not updated: Invalidate may not be called
3. Incorrect drawing: You may be using an operation that does not support hardware acceleration, need to turn off hardware acceleration, or bypass the operation
4. Throw an exception: You may be using an operation that does not support hardware acceleration, need to turn off hardware acceleration, or bypass the operation
Android Hardware acceleration