QWERTY
QWERTY

Reputation: 2315

Android ImageView Animation Not Showing

I was having some problem when trying to animate image view in Android. Basically I got an Image view which given an ID: ivEventGuide and the codes where I tried to animate it:

ivEventGuide.setVisibility(View.VISIBLE);
            final float growTo = 0.8f;
            final long duration = 1200;

            ScaleAnimation grow = new ScaleAnimation(1, growTo, 1, growTo,
                    Animation.RELATIVE_TO_SELF, 0.5f,
                    Animation.RELATIVE_TO_SELF, 0.5f);
            grow.setDuration(duration / 2);
            ScaleAnimation shrink = new ScaleAnimation(growTo, 1, growTo,
                    1, Animation.RELATIVE_TO_SELF, 0.5f,
                    Animation.RELATIVE_TO_SELF, 0.5f);
            shrink.setDuration(duration / 2);
            shrink.setStartOffset(duration / 2);
            AnimationSet growAndShrink = new AnimationSet(true);
            growAndShrink.setInterpolator(new LinearInterpolator());
            growAndShrink.addAnimation(grow);
            growAndShrink.addAnimation(shrink);
            ivEventGuide.startAnimation(growAndShrink);

            ivEventGuide.setVisibility(View.GONE);

So what I am trying to do is first I set the imageview to visible then it will perform the animation. After the animation is done, then I hide the image view and perform some other methods. But with these codes, the image view just disappear and not showing at all.

Any guides? Thanks in advance.

Upvotes: 1

Views: 1613

Answers (2)

Gunnar Karlsson
Gunnar Karlsson

Reputation: 28470

You have to listen for the completion of the animation, before you set visibility to GONE.

shrink.setAnimationListener(new AnimationListener() {
          public void onAnimationStart(Animation anim) {}

          public void onAnimationRepeat(Animation anim) {}

          public void onAnimationEnd(Animation anim) {
               ivEventGuide.setVisibility(View.GONE);
          } 
 };

Upvotes: 2

JanBo
JanBo

Reputation: 2933

Try calling startAnimation after setVisibility.

Upvotes: 0

Related Questions