作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个带有 34 个 Switch
的 Activity
,加载 Activity 没问题。
但是,当我尝试将 Switch
替换为 CheckBox
时, Activity 需要整整一秒才能加载。
这是 CheckBox
的普遍问题还是我的代码不合适?
我的 Activity 代码,已简化(仅显示 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" />
最佳答案
我认为在 XML 中创建 52 个开关或复选框会给 UI 渲染带来负担。您应该使用 RecyclerView 重用 View ,这样渲染时间会非常短。
关于android - 复选框加载速度是否比开关慢?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55673861/
我是一名优秀的程序员,十分优秀!