Android system (66)---Summary of problems related to Android hardware acceleration

Summary of Android hardware acceleration related issues


Since Android 3.0, hardware acceleration has been supported, making full use of the characteristics of GPU to make the drawing of View smoother. For example, using hardware acceleration in ListView (GridView) or WebView will make the page smoother.

 

hardware acceleration switch

 

It is turned off by default and can be turned on in the four levels of Application, Activity, Window, and View.

 

Application

 

Specify android:hardwareAccelerated="true" in the application tag in the Manifest

<application
    android:name=".MyApplication"
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:hardwareAccelerated="true"
    android:label="@string/app_name"
    android:theme="@style/AppTheme">

 

Activity

 

Specify android:hardwareAccelerated="true" in the activity tag in the Manifest

<activity
    android:name=".presentation.ui.activity.MainActivity"
    android:label="@string/app_name"
    android:hardwareAccelerated="true"
    android:screenOrientation="portrait" />

You can also turn on hardware acceleration in the Application and turn it off in the activity, just specify android:hardwareAccelerated="false" in the activity tag.

 

Window

 

getWindow().setFlags( WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED); 

View

mView.setLayerType(View.LAYER_TYPE_HARDWARE, null); 

 

Related questions

 

In actual projects, we often use hardware acceleration at the Application level or at the Activity level, hoping to get a better operating experience. In fact, hardware acceleration can indeed make our programs run more smoothly. However, Android's support for hardware acceleration is not perfect, and some drawing operations cannot work properly when hardware acceleration is turned on.

  • Flashes when the page is drawn

  • UI controls display abnormally

  • WebView loading exception

When encountering the above problems, you can consider whether hardware acceleration is enabled in the program, which is caused.

  1. Set properties on the specified pageandroid:hardwareAccelerated="false"

  2. Specify the hardware acceleration properties of a ViewmView.setLayerType(View.LAYER_TYPE_SOFTWARE, null)

  3. WebView uses hardware to greatly improve the loading efficiency, so it is recommended onPageStart()to use mView.setLayerType(View.LAYER_TYPE_HARDWARE, null);it in the onPageFinish()callback and use it in the callback mWebView.setLayerType(View.LAYER_TYPE_SOFTWARE, null).

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325474925&siteId=291194637