消失前在复选框中显示勾号

时间:2018-08-14 04:37:24

标签: android android-checkbox

我在下面有以下代码:勾选checkbox时,spinnerbuttoncheckbox消失。

但是当我运行应用程序并勾选checkbox时,checkbox只是消失而没有在框中显示“ tick”?有没有办法做到这一点,这样我就可以看到带有勾号的方框,然后这些元素就会逐渐淡入淡出?

谢谢!

代码:

newCheckbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        // makes the set disappear when checkbox is ticked.
        newCheckbox.setVisibility(View.GONE);
        newButton.setVisibility(View.GONE);
        spinner.setVisibility(View.GONE);
    }
});

3 个答案:

答案 0 :(得分:2)

尝试一下

newCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            // makes the set disappear when checkbox is ticked.

            newCheckBox.setVisibility(View.VISIBLE);
            newButton.setVisibility(View.VISIBLE);
            spinner.setVisibility(View.VISIBLE);

            newCheckBox.animate().alpha(0.0f).setDuration(1000).setListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    super.onAnimationEnd(animation);
                    newCheckBox.setVisibility(View.GONE);
                }
            });

            newButton.animate().alpha(0.0f).setDuration(1000).setListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    super.onAnimationEnd(animation);
                    newButton.setVisibility(View.GONE);
                }
            });

            spinner.animate().alpha(0.0f).setDuration(1000).setListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    super.onAnimationEnd(animation);
                    spinner.setVisibility(View.GONE);
                }
            });

        }
    });

答案 1 :(得分:0)

您可以设置复选框被选中(选中)或不手动消失。

newCheckbox.setChecked(isChecked); //isChecked = Checkbox clicked && !isChecked = checkbox not clicked

答案 2 :(得分:-1)

您可以尝试使用TimerTask和处理程序。在您提及延迟后,这将更改复选框的VISIBILITY

示例代码:

newCheckbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)     {
        // makes the set disappear when checkbox is ticked.

        new Timer().schedule(new TimerTask() {          
            @Override
            public void run() {
            // this code will be executed after 2 seconds 
            newCheckbox.setVisibility(View.GONE);      
            newButton.setVisibility(View.GONE);
            spinner.setVisibility(View.GONE);
        }
    }, 2000);

    }
});

因此,您的视图将在2秒后消失。您可以根据需要设置毫秒。