Mr. N.V.Rao
Mr. N.V.Rao

Reputation: 1082

How to hide Images after animation end in android

In my android application I have five imageviews when I click any one of that all images are animating. I set the zoomout and Zoomin animation for all the images. once the animation is finished, the selected image view is invisible. After image invisible, when i click on that imageview location it again start the animation and the image is invisible.

Zoom-In Animation:

<scale  xmlns:android="http://schemas.android.com/apk/res/android"
  android:fromXScale="1" 
  android:toXScale="5" 
  android:fromYScale="1" 
  android:toYScale="5" 
  android:pivotX="50%" 
  android:pivotY="50%" 
  android:duration="1000" 
  android:fillAfter="true">
</scale>

Zoom-out Animation

<scale  xmlns:android="http://schemas.android.com/apk/res/android"
  android:fromXScale="5" 
  android:toXScale="1" 
  android:fromYScale="5" 
  android:toYScale="1" 
  android:pivotX="50%" 
  android:pivotY="50%" 
  android:duration="1000" 
  android:fillAfter="true">
</scale>

 zoomin =AnimationUtils.loadAnimation(this, R.anim.zoom);
 zoomout=AnimationUtils.loadAnimation(this,  R.anim.zoomout);

 ImageView v2 = (ImageView) findViewById(R.id.image2);

     v2.setOnClickListener(new View.OnClickListener() 
    {
       @Override public void onClick(View v) 
       {

          v2.setAnimation(zoomin);
          v2.startAnimation(zoomin);
          v2.setAnimation(zoomout);
          v2.startAnimation(zoomout);
          v2.clearAnimation();
      }
   });

Upvotes: 0

Views: 5360

Answers (6)

Mohamed Mohamed Taha
Mohamed Mohamed Taha

Reputation: 172

You must first thing use image.clearAnimation() then hide it image.visibility = View.GONE

Upvotes: 0

Russell Elfenbein
Russell Elfenbein

Reputation: 551

You could simply change the transparency of the layer.

v2.setAlpha(0f);

Upvotes: 1

Infinite Recursion
Infinite Recursion

Reputation: 6557

This issue is occuring because you added android:fillAfter="true" in both Animation XML files.

Either remove "android:fillAfter="true" from both XMLs or keep " android:fillAfter="false" in both files.

Upvotes: 3

Gil Moshayof
Gil Moshayof

Reputation: 16761

Add this code to your animation objects:

animation.setAnimationListener(new AnimationListener() 
        {

            @Override
            public void onAnimationStart(Animation animation) { }

            @Override
            public void onAnimationRepeat(Animation animation) { }

            @Override
            public void onAnimationEnd(Animation animation) 
            {
                v2.setImageResource(R.drawable.some_transparent_image);

            }
        });

Upvotes: 9

Jitender Dev
Jitender Dev

Reputation: 6925

You need to use a Transparent Image All you need to do is when your Animation ends you need to set a transparent Image as background/scr of that image thereby replacing the previous one.

Changing the visibility of view won't solve your problem

 v2.setVisibility(View.GONE);
 v2.setVisibility(View.INVISIBLE);

As both above lead to make your view non-clickable and you won't be able to click again.

Upvotes: 0

balaji koduri
balaji koduri

Reputation: 1321

you have to handle the animation listener for that animation.

zoomin.setAnimationListener(new AnimationListener() 
    {

        @Override
        public void onAnimationStart(Animation animation) { }

        @Override
        public void onAnimationRepeat(Animation animation) { }

        @Override
        public void onAnimationEnd(Animation animation) 
        {               
            v2.setVisibility(View.GONE);
        }
    });

Upvotes: 0

Related Questions