I found that a screen appeared on a certain page on my mobile phone. Some widgets were stretched too much to cover other widgets, which was ugly. This phenomenon has a high probability. After analysis, it is found that, once this phenomenon occurs, the following log will be printed. After google, this log should be introduced by hardware acceleration. After the hardware acceleration switch is disabled at the view level, the problem does not occur again.
[Plain]
D/OpenGLRenderer (10887): GL error from OpenGLRenderer: 0x501
E/OpenGLRenderer (10887): GL_INVALID_VALUE
D/OpenGLRenderer (10887): GL error from OpenGLRenderer: 0x501
E/OpenGLRenderer (10887): The GL_INVALID_VALUE hardware accelerator switch was introduced in android3.0. It was a general impression, but we didn't turn on the hardware accelerator switch in our code. I wrote a demo, and the log shows that the hardware accelerator switch has been turned on. What does google do? Go to the official document and read the following sentence:
Beginning with Android 4.0, hardware acceleration for all windows is enabled by default if your application has set either targetSdkVersion or minSdkVersion to "14" or higher.
Here, the reason why the hardware accelerator switch is turned on is found. Why is the problem introduced on this application interface.
First, let's take a look at the concepts of android hardware acceleration. Android 3.0 introduces hardware acceleration, that is, drawing with GPU, to achieve smoother animation and smoother scrolling, and better overall performance and response to user interaction. However, hardware acceleration does not fully support all plotting operations, usually because the content is invisible, abnormal, or rendering error. If a problem occurs, you need to disable the hardware acceleration switch. To facilitate the control of the hardware acceleration switch, android provides support at four levels:
1. Application level: Add the following configuration statement to the application tag in the AndroidManifes file to enable the hardware acceleration switch. This switch applies to the entire Application.
[Html]
<Application android: hardwareAccelerated = "true"...>
<Application android: hardwareAccelerated = "true"...> 2. activity level: similarly, in the AndroidManifes file, add the following configuration statement to the activity tag to disable the hardware acceleration switch. This switch takes effect for the current activity and overwrites the application Switch in Step 1:
[Html]
<Application android: hardwareAccelerated = "true">
<Activity.../>
<Activity android: hardwareAccelerated = "false"/>
</Application>
<Application android: hardwareAccelerated = "true">
<Activity.../>
<Activity android: hardwareAccelerated = "false"/>
</Application> 3. Window level: Add the following code to the Code to enable the hardware acceleration switch at the Window level. Note: At the window level, you can only enable the hardware acceleration switch, but cannot disable it.
[Html]
GetWindow (). setFlags (
WindowManager. LayoutParams. FLAG_HARDWARE_ACCELERATED,
WindowManager. LayoutParams. FLAG_HARDWARE_ACCELERATED );
GetWindow (). setFlags (
WindowManager. LayoutParams. FLAG_HARDWARE_ACCELERATED,
WindowManager. LayoutParams. FLAG_HARDWARE_ACCELERATED); 4. View level: set the following attributes for the view in the code to disable the hardware acceleration switch at the view level. You can only disable the hardware acceleration switch. This level of decision is the highest and can cover the above three levels.
[Html]
MyView. setLayerType (View. LAYER_TYPE_SOFTWARE, null );
MyView. setLayerType (View. LAYER_TYPE_SOFTWARE, null); it is unclear why only the view on this interface has a problem. This view is not overwritten by the application, and is not complex. I have read some tips on using the hardware accelerator after google:
Reduce the number of views in your application
Avoid overdraw
Don't create render objects in draw methods
Don't modify shapes too often
Don't modify bitmaps too often
Later, I opened the android developer option to check whether there was excessive painting, and found that this interface was obviously over-drawn. Here, we can basically conclude that this interface is in violation of the second Avoid overdraw because of the high probability of opening the hardware accelerator. After reading google's Android Drawing Models instructions, I still haven't figured out what hardware acceleration is like. I don't always feel clear about this from the code, but I know that hardware acceleration is enough to solve the problems encountered in the development process. When analyzing the above problem, I found that I had removed the. 9 image and changed it to a normal resource. This problem was also corrected.