如何通过Android中的ActivityOptions在finish()上设置动画? [英] How to animate on finish() via ActivityOptions in Android?

查看:156
本文介绍了如何通过Android中的ActivityOptions在finish()上设置动画?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个具有两个活动的应用程序,即Main和Info.该应用程序以MainActivity启动,当您单击按钮时,InfoActivity从右侧滑入.当您单击另一个按钮时,InfoActivity将再次滑到右侧,并且Main返回.

I'm working on an app that has two activities, Main and Info. The App is started with the MainActivity and when you click a button the InfoActivity slides in from the right side. When you click another button, InfoActivity shall slide out to the right side again and Main returns.

这是我在MainActivity中实现动画和按钮单击的方式:

This is how I implemented the Animation and the Button Click in MainActivity:

buttonInfo.setOnClickListener(new View.OnClickListener() { 
    public void onClick(View v) {
       Intent i = new Intent(getApplicationContext(), Info.class);
       Bundle mAnimate = 
          ActivityOptions.makeCustomAnimation(getApplicationContext(),
           R.anim.ani1,R.anim.ani2).toBundle();

          startActivity(i,mAnimate);
            }
        });

我在InfoActivity中做了类似的工作,效果很好.但是,我想要并且需要有一个意图来调用finish()而不是startActivity,因为我在MainActivity中有一个服务器连接,当我调用startActivity时它会断开连接.

I did it similar in the InfoActivity, which works fine. However, i want and need to call finish() instead of startActivity with an intent, because I have a server connection in the MainActivity which disconnects when i call startActivity.

有没有想法将这样的动画应用于finish()方法或其他建议?

Any Ideas how to apply an animation like that to the finish() method or other suggestions?

推荐答案

DevBytes:窗口动画演练,您可以将您的Info.class的finish()方法替换为

As explained in the DevBytes: Window Animations walkthrough, you can replace your Info.class's finish() method with

@Override
public void finish() {
    super.finish();
    overridePendingTransition(R.anim.ani2, R.anim.ani1);
}

这篇关于如何通过Android中的ActivityOptions在finish()上设置动画?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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