我在下面有此代码:勾选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);
                }
            });

        }
    });

关于android - 消失前在复选框中显示勾号,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/51833788/

10-14 10:48