Android in the Canvas to draw graphics, and sometimes does not show one possible reason

Disclaimer: This article is a blogger original article, shall not be reproduced without the bloggers allowed. https://blog.csdn.net/One_Month/article/details/89214273

Sometimes, draw graphics, the parameters are set, but the real machine is not displayed, it may be useful that we need to turn off hardware acceleration, there are three ways
1. Set the application Manifest in

 <application
        android:name=".MyApplication"
   
        android:hardwareAccelerated="false">
 
    </application>
//但是这种,作用范围太大,如果为一些view播放动画,可能就会出现很卡的现象

2. Set the Activity Manifest in

  <activity android:name=".MainActivity"
            android:theme="@style/activityTheme"
            android:hardwareAccelerated="false">
        </activity>
//这种就为目标Activity关闭硬件加速,范围小点

3. Set on the target View

//第一种是在xml文件中
<com.example.kotlinproject.views.CircularRingView
	android:id="@+id/ring_view"
       android:layout_width="match_parent"
       android:layout_height="match_parent"
       android:layerType="software"/>```

//第二种是代码中设置
ring_view.setLayerType(View.LAYER_TYPE_SOFTWARE,null)

In this way it affirms this view has a software layer, use software rendering pipeline

Guess you like

Origin blog.csdn.net/One_Month/article/details/89214273