我想为不同的活动定义两个窗口动画样式.
这是我到目前为止:
表现:
Styles.xml:
我想要实现的是:
样式A的活动之间的转换应使用CustomActivityAnimation中定义的动画.
样式B的活动被设置为对话框,并且应该具有CustomDialogAnimation中定义的其他过渡动画.
我的问题:
从样式B关闭活动时,从不使用样式CustomDialogAnimation中的android:windowExitAnimation.而是播放样式CustomActivityAnimation中的android:activityCloseExitAnimation.
任何提示?
我们总共需要四个动画,我们将通过XML定义它们.在四个动画中,实际上有两组.第一种是将视图从当前位置移动到视野外的位置,第二种是从视图中移出视图.
定义动画XML文件:
slide_to_left.xml:
slide_to_right.xml:
slide_from_left.xml:
slide_from_right.xml:
Just as easy is animating the transition between Activities. The
Activity class provides us with a method called
overridePendingTransition that we can use to set the animation of the
exiting and entering Activities,like so:
Intent intent = new Intent(this,B.class);
startActivity(intent);
overridePendingTransition(R.anim.slide_from_right,R.anim.slide_to_left);
使用我们之前定义的动画,我们可以从视图的右侧滑入新的Activity,并将当前的Activity滑出视图左侧.
Similarly,when the new Activity is finished,we can perform the
reverse animation to have the finished Activity slide out of view to
the right,and the previous Activity slide back into view from the
left:
finish();
overridePendingTransition(R.anim.slide_from_left,R.anim.slide_to_right);
Handling on back button:
@Override
public void onBackPressed() {
super.onBackPressed();
overridePendingTransition(R.anim.slide_from_left,R.anim.slide_to_right);
}