在Android的&QUOT新活动,从侧面&QUOT进入; [英] New Activity in Android "enter from the side"

查看:99
本文介绍了在Android的&QUOT新活动,从侧面&QUOT进入;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是去一个新的活动,但使它看起来像活动幻灯片的左侧和新的活动进入画面的最佳方法是什么?我使用的意图来调用新的活动,是该办法做到这一点,如果我希望应用程序是轻量级的?

What's the best way to go to a new activity but make it look like the activity slides to the left and the new activity enters the screen? I am using intents to call the new activity, is that the way to do it if I want the application to be lightweight?

要解释好一点:在我的Andr​​oid手机,我可以刷卡的主场MENY到右侧视图,然后从左侧进入一个朋友流和发生在屏幕上。我想这样做在我和buttonclicks的应用程序,它的滑动我是后。 谢谢!

To explain a bit better: on my Android phone I can swipe the view with the home meny to the right and then enters a friend stream from the left and takes place on the screen. I want to do it in my app with buttonclicks, it's the "sliding" i am after. THanks!

推荐答案

在Android操作系统2.1或更高版本我想你可以使用 OverridePendingTransition()方式来提供一种过渡的活动,动画您的所期待的。

In android OS 2.1 or later I think you can use the OverridePendingTransition() method to provide the kind of transition between activities animations you are looking for.

首先,定义的 / RES /一对夫妇的动画资源的动画/ 的。这里有一个名为 right_slide_out.xml

Firstly, define a couple of animation resources in /res/anim/. Here is one that is named right_slide_out.xml :

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_decelerate_interpolator">
    <translate
        android:fromXDelta="0"
        android:toXDelta="100%p"
        android:duration="500"
    />
</set>

这是另一个叫 right_slide_in.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_decelerate_interpolator">
    <translate
        android:fromXDelta="100%p"
        android:toXDelta="0"
        android:duration="700"
    />
</set>

然后,当你开始新的活动,使用OverridePendingTransition方法如下所示:

Then, when you are starting the new activity, use the OverridePendingTransition method as in:

startActivity(intent);
overridePendingTransition  (R.anim.right_slide_in, R.anim.right_slide_out);

这应该处理的过渡动画启动该活动。

That should handle the transition animations for starting the activity.

对于反向,当活动结束和你将回来到原来的,它更云里雾里一点。

For the reverse, when that activity finishes and youre coming back to the original one, it's a bit more foggy.

如果你有一些UI控件,结束该活动,并呼吁Activity.finish(),那么你可以之后,仅仅增加overridePendingTransition()。

If you have some UI control that ends that activity and calls Activity.finish(), then you can just add the overridePendingTransition() right after that.

要处理,用户通过结束pressing后退按钮活动的情况下,使用类似以下内容:

To handle the case where the user ends the activity by pressing the back button, use something like the following:

@Override
public void onBackPressed() 
{

    this.finish();
    overridePendingTransition  (R.anim.right_slide_in, R.anim.right_slide_out);
}

这篇关于在Android的&QUOT新活动,从侧面&QUOT进入;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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