1

Why does mImageView.setVisibility not works after I use one animation?

I have this code works fine (CODE1)...

    tbnVisible.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        if (isChecked) {
                mImageView.setVisibility(View.VISIBLE);
            } else {
                mImageView.setVisibility(View.INVISIBLE);
            }
        }
    });

Any time I click at the ToggleButton (tbnVisible) and my CODE1 run perfectly and my ImageVies appears and hide. After that, I run the CODE2 to run one Animation with fade in the same View (mImageView).

THIS IS THE CODE2...

    btnAlphaAPI.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            AlphaAnimation fadeOut = new AlphaAnimation(1.0f, 0.0f);
            AlphaAnimation fadeIn = new AlphaAnimation(0.0f, 1.0f);

            mAlphaAnimation = mFadeOut ? fadeIn : fadeOut;
            mAlphaAnimation.setDuration(2000);
            mAlphaAnimation.setFillAfter(true);
            mImageView.startAnimation(mAlphaAnimation);

            mAlphaAnimation.setAnimationListener(new Animation.AnimationListener() {
                @Override
                public void onAnimationEnd(Animation animation) {
                    mFadeOut =  !mFadeOut;
                }
            });
        }
    });

This code run perfectly too... until know, that's ok, the problem is when I try to run de CODE1 again. When I click in the ToggleButton (tbnVisible) not happens more with my mImageView. Just the CODE1 not works more after run the CODE2.

Somebody know what's happens?

Thanks so much

Biruel Rick
  • 776
  • 1
  • 8
  • 17

1 Answers1

1

From Why doesn't setVisibility work after a view is animated?, have you tried using clearAnimation on the View?

Community
  • 1
  • 1
Arthulia
  • 190
  • 13