加载的复选框是否比交换机慢?

问题描述 投票:1回答:1

我有一个Activity与34 Switch,加载活动很好。

但是,当我尝试用Switch替换CheckBox时,活动需要一整秒才能加载。

这是CheckBox的一般问题还是我的代码不合适?

我的活动代码,简化(仅显示1个CheckBox

public class Myactivity extends AppCompatActivity {
CheckBox MyCheckbox1;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_myactivity);

        MyCheckbox1 = findViewById(R.id.mycheck1);
        Mycheckbox1.OnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            onCheckedChanged(CompoundButton view, boolean isChecked) {
                if(((CompoundButton) view).isChecked()){
                    //do something
                }else{
                    //do something else
                }
            }
        }
    }
}

我的复选框XML代码:

<CheckBox
                android:id="@+id/mycheck1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/Option1"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintTop_toTopOf="parent" />
android xml android-layout checkbox
1个回答
0
投票

我认为在XML中创建52个开关或Checkbox会加重UI渲染。您应该使用RecyclerView重用视图,这样渲染时间就会非常短。

© www.soinside.com 2019 - 2024. All rights reserved.