创建一个“向左滑动”动画。然后调整新视图的动画,所以当动画开始时,您将其他动画应用并启动到其他视图。例如,
Animation animation = AnimationUtils.loadAnimation(context,
R.anim.slide_in_right);
animation.setDuration(TIME);
animation.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
// TODO - Set and start other animation here
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
}
});
view.startAnimation(animation);
[编辑]
// First, define and infalte the view that will be incoming
View upcomingView = inflater.inflate(...);
// Next, we'll set the animation up
Animation animation = AnimationUtils.loadAnimation(context,
R.anim.slide_in_right);
animation.setDuration(TIME);
animation.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
Animation outAnimation = AnimationUtils.loadAnimation(context,
R.anim.slide_out_left);
upcomingView.startAnimation(outAnimation);
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
}
});
currentView.startAnimation(animation); // This will start the animation defined above, which will also set and start the animation for the incoming object
问题是,将被应用到新的视图。另一个视图甚至不在当前的Activity中,所以如何获得它的句柄才能使其动画化? – theblitz 2012-08-08 14:24:33
所以你需要定义两个单独的视图。一个视图,我们将其称为currentView,需要具有上述定义的动画。这将使它开始滑向右侧。那么你需要另一个视图(已经膨胀),我将称之为即兴视图。在“onAnimationStart”中,您需要将左侧动画中的幻灯片应用于,然后为其调用“开始”。我会更新我的原始文章,以便更清楚地看到代码。 – RyanInBinary 2012-08-08 14:34:51