为什么视图的可见性会随机变化?

时间:2018-10-22 16:03:21

标签: java android

我对TextView的公开程度感到困惑。我希望它逐渐消失,所以我做到了:

 Log.d("TESTCLICK", "ForgotTextView Visibility 1 : " + Integer.toString(forgotTextView.getVisibility()));

 forgotTextView.setVisibility(View.VISIBLE);

 Log.d("TESTCLICK", "ForgotTextView Visibility 2 : " + Integer.toString(forgotTextView.getVisibility()));
 forgotTextView.setAlpha(0f);

 ViewPropertyAnimator editTextNameAnimator = nameEditText.animate().alpha(0f).setDuration(1000);
 ViewPropertyAnimator editTextPasswordAnimator = confirmEditText.animate().alpha(0f).setDuration(1500);

 editTextNameAnimator.setListener(new Animator.AnimatorListener() {
                @Override
                public void onAnimationStart(Animator animator) {

                }

                @Override
                public void onAnimationEnd(Animator animator) {
                    nameEditText.setVisibility(View.GONE);
                    Log.d("TESTCLICK", "ForgotTextView Visibility 4 : " + Integer.toString(forgotTextView.getVisibility()));
                }

                @Override
                public void onAnimationCancel(Animator animator) {

                }

                @Override
                public void onAnimationRepeat(Animator animator) {

                }
            });

 editTextPasswordAnimator.setListener(new Animator.AnimatorListener() {
                @Override
                public void onAnimationStart(Animator animator) {

                }

                @Override
                public void onAnimationEnd(Animator animator) {
                    confirmEditText.setVisibility(View.GONE);
                    Log.d("TESTCLICK", "ForgotTextView Visibility 5 : " + Integer.toString(forgotTextView.getVisibility()));

                }

                @Override
                public void onAnimationCancel(Animator animator) {

                }

                @Override
                public void onAnimationRepeat(Animator animator) {

                }
            });

 editTextNameAnimator.start();
 editTextPasswordAnimator.start();
 forgotTextView.animate().alpha(1.0f).setDuration(1000).start();

 loginButton.animate().translationYBy(-100f).setDuration(1000).start();

 Log.d("TESTCLICK", "ForgotTextView Visibility 3 : " + Integer.toString(forgotTextView.getVisibility()));

所以我基本上将TextView的可见性更改为VISIBLE,将其alpha设置为0,然后将其与其他视图一起设置动画,但是这些日志的输出看起来像这样enter image description here

因此,直到第4个对数为止一切正常,但是到了第5个,我的TextView消失了,好像它的可见性又变回了GONE,就像开始时一样(我特别更改了此设置动画的持续时间为1500(仅用于检查日志),为什么会发生这种情况?

编辑: 解决方案是在forgotTextView动画中添加侦听器,并在动画结束时将其可见性更改为VISIBLE再次,因此就像对其进行两次更改一样,这种更改不会改变单独GONE(或将其覆盖,但您将其覆盖)。我仍然不知道为什么会这样

0 个答案:

没有答案