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

Showing tick in checkbox before disappearing

我有以下代码:当您勾选 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);
    }
});

试试这个,

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);
                }
            });

        }
    });

您可以尝试为此使用 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 秒后淡出。您可以根据需要设置毫秒数。

您可以在复选框消失之前手​​动设置复选框是否被选中(勾选)或不被选中。

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