Android ViewFlipper 动画
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1919169/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Android ViewFlipper Animation
提问by Ljdawson
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.
我被困在一个让我发疯的简单问题上。基本上我有 2 个 ImageViews,我试图让第一个显示一秒钟,然后淡出以显示第二个。我一直在研究使用 ViewFlipper,下面是示例代码,但动画不存在。
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!
我不确定我是否使用 viewFlipper 在正确的轨道上,所以任何帮助将不胜感激!
Cheers
干杯
回答by Dan Lew
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.
当我使用标准android.R.anim.fade_in
和android.R.anim.fade_out
. 这让我相信这个问题与你的淡入淡出动画有关;尝试使用内置的 Android 淡入淡出,看看是否有帮助。
Also, you should be using ImageView.setImageResource()
or ImageView.setImageDrawable()
rather than ImageView.setBackgroundDrawable()
.
此外,您应该使用ImageView.setImageResource()
or ImageView.setImageDrawable()
而不是ImageView.setBackgroundDrawable()
.