如何调用Android的另一个活动时,提供动画? [英] How to provide animation when calling another activity in Android?
问题描述
我有两个活动A和B.我想有收缩动画时, 活动A调用B和最大化的动画时,活动B调用答:我并不需要动画的XML文件这一点。
I have two Activities A and B. I want to have the shrink Animation when Activity A calls B and maximize animation when Activity B calls A. I don't need the animation xml files for this.
当我们调用另外一个Activity在Android中也给出了其默认的动画,然后调用缩水动画。
When we call another Activity in Android it gives its default animation and then it calls shrink animation.
我想是不应该发生的默认的动画,我想要的动画应该发生。
What I want is that the default animation should not occur and the animation that I want should occur.
我们实际上可以给动画调用另一个活动时,?
Can we actually give the animation when calling another Activity?
推荐答案
您可以prevent默认的动画(从右侧滑入)与 Intent.FLAG_ACTIVITY_NO_ANIMATION
标志你的意图。
You can prevent the default animation (Slide in from the right) with the Intent.FLAG_ACTIVITY_NO_ANIMATION
flag in your intent.
即:
Intent myIntent = new Intent(context, MyActivity.class);
myIntent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
context.startActivity(myIntent);
然后在您的活动中,你只需指定自己的动画。
then in your Activity you simply have to specify your own animation.
这也适用于1.5 API(3级)。
This also works for the 1.5 API (Level 3).
有关针对API级别的应用程序5+有活动<一href="http://developer.android.com/reference/android/app/Activity.html#overridePendingTransition%28int,%20int%29"><$c$c>overridePendingTransition$c$c>方法。花费的传入和传出动画两个资源的ID。 的id 0
将禁止动画。在 startActivity
调用后立即调用此。
For apps targeting API level 5+ there is the Activities overridePendingTransition
method. It takes two resource IDs for the incoming and outgoing animations. An id of 0
will disable the animations. Call this immediately after the startActivity
call.
即:
startActivity(new Intent(this, MyActivity.class));
overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
这篇关于如何调用Android的另一个活动时,提供动画?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!