Android 一个接一个地设置两个图像的动画
我正在用从左下角到上方的图像设置两个布局的动画。当我同时设置这些图像的动画时,效果很好。但我想一个接一个地设置它们的动画。这意味着第一个底部布局将从左下角到上方设置动画。然后它上面的布局将从左下角到上方设置动画。 为此,我尝试了下面的代码,但效果并不理想。我尝试使用postDelayed()方法设置第二个图像的动画。但首先我看到一个布局动画和第二个布局静态,然后我看到两个图像动画。正确的方法应该是什么Android 一个接一个地设置两个图像的动画,android,animation,android-imageview,Android,Animation,Android Imageview,我正在用从左下角到上方的图像设置两个布局的动画。当我同时设置这些图像的动画时,效果很好。但我想一个接一个地设置它们的动画。这意味着第一个底部布局将从左下角到上方设置动画。然后它上面的布局将从左下角到上方设置动画。 为此,我尝试了下面的代码,但效果并不理想。我尝试使用postDelayed()方法设置第二个图像的动画。但首先我看到一个布局动画和第二个布局静态,然后我看到两个图像动画。正确的方法应该是什么 Handler fbanimation; bottomUp = AnimationUti
Handler fbanimation;
bottomUp = AnimationUtils.loadAnimation(this,
R.anim.loginbottomup);
ggin.setVisibility(View.VISIBLE);
ggin.startAnimation(bottomUp);
fbanimation.postDelayed(new Runnable() {
@Override
public void run() {
afn.setVisibility(View.VISIBLE);
afn.startAnimation(bottomUp);
}
},1000);
loginbottomup.xml
<set
android:shareInterpolator="false">
<translate android:fromXDelta="-300%" android:toXDelta="0%"
android:fromYDelta="300%" android:toYDelta="0%"
android:duration="1000"/>
</set>
您需要一个名为
AnimationListener
的侦听器,将其附加到底部动画中,并在动画结束时运行下一个动画,该动画位于onAnimationEnd
方法中
bottomUp.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
// run the next animation here
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
研究如何使用该类:
这里的也应该有很大的帮助。这是使用
动画集的代码示例。假设您有两个ImageView
s,则iv
在其完成iv2
启动时开始和结束
iv1 = (ImageView) findViewById(R.id.imageView1); //first image
iv2 = (ImageView) findViewById(R.id.imageView2); // second image
Animation iv1anim = AnimationUtils.loadAnimation(this, R.anim.abc_slide_out_bottom);
Animation iv2anim = AnimationUtils.loadAnimation(this, R.anim.abc_slide_in_bottom);
// the animations are in-built
iv1.setAnimation(iv1anim); // setting the respective anims
iv2.setAnimation(iv2anim);// setting the respective anims
iv1anim.setStartTime(0); // it will start quickly
iv2anim.setStartOffset(iv1anim.getDuration());// its going to delay,for the duration
// of the first image. in millieseconds,so there will be no seconds wait
final AnimationSet anim = new AnimationSet(false);
anim.addAnimation(iv1anim); // the rest is cheese
anim.addAnimation(iv2anim);
anim.startNow();
这就是你想要的,对吗?希望对你有帮助。总是向上投票,我喜欢上传:)我想让名为“first”的imageview先进行动画制作,动画制作完成后,再让名为“second”的imageview进行动画制作..我该怎么做?@bhunneshvarma为2个imageview创建2个动画Utils,然后像上面的示例一样附加animationlitener,并在onAnimationEnd
中创建另一个animationUtils并运行它。我尝试了你的答案。现在似乎也有问题。当我同时设置两个布局的动画时,效果很好。但是如果我一个接一个地设置动画,似乎会出现一些边距问题,因为布局似乎是从顶部切入的。我已经发布了有问题的布局代码。你知道animatorSet
?检查一下,这正是你需要的。。所以,你所要做的就是把你的动画放在一个列表中,然后使用答案中的第一个选项,安卓将完成这个任务rest@Elltz我想让名为“first”的imageview首先进行动画制作,动画制作完成后,再让名为“second”的imageview进行动画制作..我该怎么做?请参考John D。回答我必须将动画1
指定给first
和animation2
到second
我看不出我的帖子是如何链接的,这两个答案无法满足您的要求。将动画设置为视图,并使用animatorSet播放动画,或者使用自定义方式,让侦听器播放第一个动画,并在其结束时启动第二个动画,这是Rod提供的答案。先生,你是初学者吗?@Elltz是的,我是freasher..假设我想为两个imagview.imageview制作动画,名为first
“[首先设置动画,在动画完成后,然后使用名为second
的imageview设置动画..我可以使用AnimatorSet进行设置吗?参考Joh的回答,我将如何将动画1分配给first
,将动画2分配给second
?请帮助我使用代码您尝试过我的方法吗?我希望使用名为'first'的imageview设置给anima首先,在其动画完成后,然后名为“second”的imageview进行动画制作。我如何做?我必须将animation1
分配给first
和animation2
分配给second
AnimatorSet类使用Animator对象(与动画对象相反)我发现使用它比用XML定义动画更简单,因此可以使用ObjectAnimator类创建animator1对象,然后将它们传递到play()和after()方法中。
iv1 = (ImageView) findViewById(R.id.imageView1); //first image
iv2 = (ImageView) findViewById(R.id.imageView2); // second image
Animation iv1anim = AnimationUtils.loadAnimation(this, R.anim.abc_slide_out_bottom);
Animation iv2anim = AnimationUtils.loadAnimation(this, R.anim.abc_slide_in_bottom);
// the animations are in-built
iv1.setAnimation(iv1anim); // setting the respective anims
iv2.setAnimation(iv2anim);// setting the respective anims
iv1anim.setStartTime(0); // it will start quickly
iv2anim.setStartOffset(iv1anim.getDuration());// its going to delay,for the duration
// of the first image. in millieseconds,so there will be no seconds wait
final AnimationSet anim = new AnimationSet(false);
anim.addAnimation(iv1anim); // the rest is cheese
anim.addAnimation(iv2anim);
anim.startNow();