开发者

Android ViewFlipper Animation

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


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().


Have you tried:

    mFlipper.setInAnimation(AnimationUtils.loadAnimation(this,
             R.anim.fade_in));
     mFlipper.setOutAnimation(AnimationUtils.loadAnimation(this,
             R.anim.fade_out));

Taken from here

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜