简体   繁体   English

"为什么android的checkbox这么慢?"

[英]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 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><\/code><\/pre>

MainActivity.java 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)); } }<\/code><\/pre>

There is only one Checkbox in the page, this will cost 200ms.页面中只有一个复选框,这将花费 200 毫秒。 If there are 3 or 5 checkbox in activity_main.xml, will cost 1s.如果 activity_main.xml 中有 3 或 5 个复选框,将花费 1s。 What happend?发生了什么事?

I compared Switch to Checkbox.我将 Switch 与 Checkbox 进行了比较。 Obviously Switch is very very better than Checkbox.显然 Switch 比 Checkbox 好得多。 If i want to keep to use Checkbox, what should i do?如果我想继续使用复选框,我该怎么办?

"

Why does it happen ?为什么会这样?<\/h2>

This is happening because the Checkbox<\/code> class is very complicated(too much code 😠).发生这种情况是因为Checkbox<\/code>类非常复杂(代码太多😠)。

What is the solution ?解决办法是什么 ?<\/h2>
  1. You can create a custom layout.您可以创建自定义布局。<\/li>
  2. You can use a library.您可以使用库。<\/li><\/ol>

    How to implement ?如何实施?<\/h2>

    1.Custom layout 1.自定义布局<\/h3>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM