- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
今天用的是安卓机,性能很差。我发现复选框加载速度很慢。例如:
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>
主 Activity .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));
}
}
页面中只有一个Checkbox,耗时200ms。如果 activity_main.xml 中有 3 或 5 个复选框,则花费 1 秒。发生了什么事?
我将 Switch 与 Checkbox 进行了比较。显然 Switch 比 Checkbox 好很多。如果我想继续使用 Checkbox,我该怎么办?
最佳答案
发生这种情况是因为 Checkbox
类非常复杂(代码太多 😠)。
水平
方向的LinearLayout
。ImageView
和一个 TextView
。<LinearLayout
android:id="@+id/checkbox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="7dp">
<ImageView
android:id="@+id/checkImageView"
android:layout_width="30dp"
android:layout_height="30dp"
android:src="@drawable/checked"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This is the text for checkbox."
android:layout_gravity="center_vertical"
android:layout_marginStart="15dp"/>
</LinearLayout>
在你的类里面添加这个
boolean isChecked = true
现在它的功能是这样的
LinearLayout checkBox = findViewById( R.id.checkbox );
ImageView checkBoxImage = findViewById( R.id.checkImageView );
checkBox.setOnClickListener( v -> {
final Bitmap bmap = ((BitmapDrawable)checkBoxImage.getDrawable()).getBitmap();
Drawable myDrawable = getResources().getDrawable(R.drawable.checked);
final Bitmap myLogo = ((BitmapDrawable) myDrawable).getBitmap();
if (bmap.sameAs(myLogo)){
//it is checked
isChecked = false;
checkBoxImage.setImageResource( R.drawable.unchecked );
}else {
isChecked = true;
checkBoxImage.setImageResource( R.drawable.checked );
}
} );
setChecked(boolean checked); //by default, it's wthout animation
setChecked(boolean checked, boolean animate); //pass true to animate
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sample);
final CustomCheckBox scb = (CustomCheckBox) findViewById(R.id.scb);
scb.setOnCheckedChangeListener(new CustomCheckBox.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CustomCheckBox checkBox, boolean isChecked) {
Log.d("CustomCheckBox", String.valueOf(isChecked));
}
});
}
由于 Decent Dabbler
收到的评论,我现在想起来它忘记了什么。我其实忘了说加载时间太长的文件是xml
文件。这可以证明我们并不总是使用类吧?只是 xml
中的 View 。如果你打开复选框的xml
文件,你会发现它太大了。
关于java - 为什么android的checkbox这么慢?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68388846/
在检查复选框时我发现有写 CheckBox checkbox = (CheckBox)sender 在 checkBox1_CheckedChanged 事件上。 请解释一下这是什么意思? 最佳答案
我正在使用来自命名空间 System.Windows.Forms 的 ToolTip 类编辑我的 Web 应用程序;我的代码中有几个复选框,因此显示此错误: 'CheckBox' is an ambi
我正在制作 Bootstrap 复选框下拉菜单,选项包含在 中。处理点击的标签,但我也有一个 在 a 标签内。 当用户按下实际复选框而不是仅按下 时,就会出现我的问题。元素。两者都被点击并且发生了
TLDR:使用defaultChecked而不是checked,工作jsbin . 尝试设置一个简单的复选框,在选中时会划掉其标签文本。由于某种原因,当我使用该组件时,handleChange 没有被
我想拥有它,所以如果复选框为 NULL 或 0,则它不像值为 1 时那样喜欢。另外,有没有办法将选中的框限制为 10 个? 当前代码: if(isset($_POST['submit'])){//to
如果我选中一个复选框,下拉列表应该只显示在该复选框旁边,但它会显示在它下面的所有其他复选框中。 这是我在 html 代码中使用的 css .sub-nav { display: none; } inp
我在警报对话框中有一个带有复选框的数据表,当我单击该复选框时,它没有选中(选中=选中)该框。我跟着这个video 这是我的尝试 import 'package:flutter/material.dar
如果单独使用,以下代码效果很好, Angular6.0 不允许 [(ngModel)] 与 FormGroup (Reactive Forms)。 As 在 angular 6.0 中已弃用,并将在
那么我应该使用哪个来选择元素?我仅使用复选框作为示例,这个问题涉及所有表单元素。 实际上,当我们这样做时,哪个更快: li:first 或 li:eq(0) ? 最佳答案 来自the document
问题 : 我有一个列表框,其中列表框是复选框。在第一次单击时,复选框被选中并选中。在第二次单击时,仅设置复选框。可以使用箭头键重新选择不同的复选框。我的目标是,首先选中该复选框,然后再检查(再次单击它
我似乎无法弄清楚如何让复选框和相关文本出现在一行上。文本很短,所以它似乎不是宽度问题。 我尝试在控件上设置 display:inline,但是当它呈现时,在输入和标签周围添加了一个跨度,并且具有 di
创建带有复选框列的 Table 非常容易,例如,使用 SWT.CHECK 标志。但是如何使某些表格行中的复选框不可编辑而其他行中的复选框保持可编辑? 最佳答案 我不知道这样做的简单方法。 但我看到了两
是否可以使用 TogglerBar 而不是 2 个复选框来显示或不显示不同的形状。 TogglerBar 的每个按钮中都写有绿色和红色? Manipulate[ Graphics[{If[thePin
我需要更改 Windows Phone 8 中 LongListMultiSelector 的复选框的颜色,因为我的背景是白色,这可能吗? 谢谢。 最佳答案 为此,您必须首先通过在 visual st
我有一个带有插件 Slick.CheckboxSelectColumn 的网格。 是否可以在没有 Jquery 的情况下隐藏某些行中的复选框?我想可以使用 Formatter。 这是带有 slickg
所以我有这个... 在这里,id 是有道理的值在引号中,因为它是一个字符串标识符。但是type呢?值(value)?不是 checkbox一种类型,例如 String 和 Boolean?为什么我总
问题: 如果用户选中了复选框,我将尝试验证下拉列表,如您在屏幕一中所见。 问题: 那么,如果用户选择了标题中的所有复选框,我该如何验证复选框呢?如您所见,屏幕二。如果我选中所有复选框,那么我希望启动验
我知道它有点重复,我正在尝试以不同的方式做到这一点,从而重新发布这个问题。 我想要实现的是,当有人“取消选中”OSPF 复选框时..被动接口(interface)检查也应该自动“取消选中”。我正在尝试
这是代码(是的,我使用的是基本的 reset.css): .checkbox { border: 1px solid black; width: 10px; height: 10px; }
我正在尝试显示多组带有标题复选框的复选框,如下图所示。 从数据库中我得到这样的数据, CODE SUBCODE DESCR DESCR
我是一名优秀的程序员,十分优秀!