Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android ViewFlipper Animation

Tags:

android

I'm stuck on a simple problem which is driving me nuts. Basically I have 2 ImageViews, I'm trying to have the first show for a second, then fade out to show the second. I've been looking into using ViewFlipper, example code below, but the animation is non-existent.

ViewFlipper mFlipper = new ViewFlipper(this);

ImageView i = new ImageView(this);
i.setBackgroundDrawable(getResources().getDrawable(R.drawable.c1));
ImageView i2 = new ImageView(this);
i2.setBackgroundDrawable(getResources().getDrawable(R.drawable.c2));

mFlipper.setInAnimation(AnimationUtils.loadAnimation(this,
        R.anim.fade));
mFlipper.setOutAnimation(AnimationUtils.loadAnimation(this,
        R.anim.fade));
mFlipper.addView(i);
mFlipper.addView(i2);
mFlipper.startFlipping();
setContentView(mFlipper);

I'm not sure if I'm even on the right track using a viewFlipper so any help would be greatly appreciated!

Cheers

like image 751
Ljdawson Avatar asked Dec 17 '09 02:12

Ljdawson


People also ask

What is ViewFlipper in Android?

android.widget.ViewFlipper. Simple ViewAnimator that will animate between two or more views that have been added to it. Only one child is shown at a time. If requested, can automatically flip between each child at a regular interval.

What is fade in Android?

In Android Animations are the visuals that are added to make the user interface more interactive, clear and good looking. Fade In and Fade out animations are used to modify the appearance of any view over a set interval of time so that user can be notified about the changes that are occurring in our application.


1 Answers

I see no problems with your code, when I use the standard android.R.anim.fade_in and android.R.anim.fade_out. This leads me to believe that the issue has to do with your fade animations; try using the built-in Android fades and see if that helps.

Also, you should be using ImageView.setImageResource() or ImageView.setImageDrawable() rather than ImageView.setBackgroundDrawable().

like image 63
Dan Lew Avatar answered Oct 21 '22 14:10

Dan Lew