活动过渡动画中的Andr​​oid [英] Activity Transition Animations in Android

查看:159
本文介绍了活动过渡动画中的Andr​​oid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想申请一个活动转变像一个HTC的手机有:当你开始一个新的活动有一个滑动从右到左的,但是当你preSS的后退按钮返回到previous活动,有左到右的动画幻灯片。

I want to apply an activities transition like the one that HTC phones have: When you start a new Activity there is a slide right-to-left, but when you press the back button to return to the previous Activity, there is a slide left-to-right animation.

我已经使用 overridePendingTransition onResume 我的活动,模拟滑从右到左的动画,但是当我preSS后退按钮,同样的动画是执行,这是错误的(从结果的角度来看)。

I have used overridePendingTransition in the onResume of my Activities to simulate the slide right to left animation, but when I press the back button, the same animation is executed which is wrong (from a result perspective).

因此​​,我想问一下如何管理具有不同动画的活动,一个是创建时的,一当用户preSS返回键。

Thus I would like to ask how to manage having different animations for an Activity, one for when it is created, and one for when the user press back key.

非常感谢!

推荐答案

要定义一个动画,当用户presses后退按钮,你必须重写 onBack pressed()活动和使用 overridePendingTransition()的有:

To define an animation when the user presses the back button, you have to override onBackPressed() in your Activity and use overridePendingTransition() in there:

public void onBackPressed() {
    super.onBackPressed();
    overridePendingTransition(R.anim.in_from_left, R.anim.out_to_right);
}

因此​​,当后退按钮获得pressed这个动画将只显示。

So this animation will only be shown when the back button gets pressed.

要一个新的活动打开时设置动画,你只需要定义你的动画后调用 startActivity()或类似的:

To set an animation when a new Activity opens, you just have to define the animation after you called startActivity() or similar:

startActivity(some_intent);
overridePendingTransition(R.anim.in_from_right, R.anim.out_to_left);

这篇关于活动过渡动画中的Andr​​oid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆