Android 使用 FLAG_ACTIVITY_CLEAR_TOP 的活动之间的动画过渡
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3504619/
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
Animation transition between activities using FLAG_ACTIVITY_CLEAR_TOP
提问by Romain Piel
In my android app, I'm making a method that pop all activities and bring up the first activity.
在我的 android 应用程序中,我正在制作一种弹出所有活动并调出第一个活动的方法。
I use this code:
我使用这个代码:
Intent intent = new Intent(this, MMConnection.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
this.startActivity(intent);
As I noticed that the transition was still a left to right animation, does someone know if there is a way to change system animation when starting an activity?
当我注意到过渡仍然是从左到右的动画时,有人知道是否有办法在开始活动时更改系统动画?
Actually, I'd ideally like to have a right to left transition (like when the return button is tapped)
实际上,我希望有一个从右到左的过渡(比如点击返回按钮时)
thanks for help!
感谢帮助!
回答by E-Riz
CoolMcGrr is right, you want to use overridePendingTransition(int enterAnim, int exitAnim)
.
CoolMcGrr 是对的,您想使用overridePendingTransition(int enterAnim, int exitAnim)
.
To specifically get the standard "back button" transition, I use these as the enterAnim
and exitAnim
transitions:
为了专门获得标准的“后退按钮”转换,我使用这些作为enterAnim
和exitAnim
转换:
push_right_in.xml
push_right_in.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromXDelta="-100%p" android:toXDelta="0" android:duration="@android:integer/config_shortAnimTime"/>
<alpha android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="@android:integer/config_shortAnimTime" />
</set>
push_right_out.xml
push_right_out.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromXDelta="0" android:toXDelta="100%p" android:duration="@android:integer/config_shortAnimTime"/>
<alpha android:fromAlpha="1.0" android:toAlpha="0.0" android:duration="@android:integer/config_shortAnimTime" />
</set>
回答by CoolMcGrrr
You should take a look Activity.overridePendingTransition().
你应该看看Activity.overridePendingTransition()。
Of course, this requires that you run at least version 2.0 of the SDK.
当然,这要求您至少运行 2.0 版的 SDK。
回答by dzeikei
Problem occurs nowadays because pre-ICS and ICS have different built-in activity transitions. This is much cleaner than defining your own animation and SDK independant:
现在出现问题是因为 pre-ICS 和 ICS 具有不同的内置活动转换。这比定义你自己的动画和 SDK 独立得多:
Intent intent = new Intent(this, MMConnection.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_NO_ANIMATION);
this.startActivity(intent);
finish();
This will start the activity (not visible yet) and play the "activity finish" transition to the new activity.
这将启动活动(尚不可见)并播放“活动完成”过渡到新活动。
回答by Cabezas
I used this code:
我使用了这个代码:
overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
You can see these examples in GmailAnimationor LopeAnimations. Also you can see more in this Blog.
您可以在GmailAnimation或LopeAnimations 中看到这些示例。你也可以在这个博客中看到更多。