This article from: blog. Chenming. Info/blog / 2012/0… The problem is that on some Android 4.0 devices, when a View is refreshed, the screen is broken and some of the views on the screen are out of place. Adb Logcat: 0x501 OpenGLRenderer: 0x501

09-18 14:34:39.090: DEBUG/OpenGLRenderer(3104): GL error from OpenGLRenderer: 0x501
09-18 14:34:39.386: DEBUG/OpenGLRenderer(3104): GL error from OpenGLRenderer: 0x501
09-18 14:34:39.656: DEBUG/OpenGLRenderer(3104): GL error from OpenGLRenderer: 0x501Copy the code

From this log, the initial suspicion is that hardware acceleration is the cause of the problem. After analysis, it is found that the use of a more complex custom View may lead to hardware accelerated rendering errors.

Advantages and disadvantages Of hardware acceleration Hardware acceleration can use the GPU to speed up 2D image rendering, but hardware acceleration does not fully support all rendering operations, for custom views, hardware acceleration may cause errors in rendering. If you have custom views, you need to test them on hardware accelerated devices, and if rendering issues occur, you need to turn hardware accelerated off.

Enabling and disabling hardware acceleration Hardware acceleration can be enabled or disabled at different levels: Application Activity Windows View

Application level Controls hardware acceleration at the Applciation level:

<application android:hardwareAccelerated="true" .>Copy the code

The Activity level controls whether hardware acceleration is enabled for individual activities:

<application android:hardwareAccelerated="true">
    <activity . />
    <activity android:hardwareAccelerated="false" />
</application>Copy the code

Window level

getWindow().setFlags(
    WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,
    WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);Copy the code

View level Disables hardware acceleration on the specified View:

myView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);Copy the code

Or use Android :layerType= “software” to turn off hardware acceleration:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:paddingLeft="2dp"
    android:layerType="software"
    android:paddingRight="2dp" >Copy the code

How can I tell if a View has hardware acceleration enabled

View.isHardwareAccelerated()// returns true if the View is attached to a hardware accelerated window.
Canvas.isHardwareAccelerated()// returns true if the Canvas is hardware acceleratedCopy the code