創建一個「向左滑動」動畫。然後調整新視圖的動畫,所以當動畫開始時,您將其他動畫應用並啓動到其他視圖。例如,
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