Wednesday, 26 January 2022

Why checkbox of android is so slow?

Today, I used an Android machine with poor performance. I found the checkbox loading is very slow. For example:

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <CheckBox
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
    
</LinearLayout>

MainActivity.java

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        long t1 = System.currentTimeMillis();
        setContentView(R.layout.activity_main);
        System.out.println("main cost: " + (System.currentTimeMillis()  - t1));
    }
}

There is only one Checkbox in the page, this will cost 200ms. If there are 3 or 5 checkbox in activity_main.xml, will cost 1s. What happend?

I compared Switch to Checkbox. Obviously Switch is very very better than Checkbox. If i want to keep to use Checkbox, what should i do?



from Why checkbox of android is so slow?

No comments:

Post a Comment