如何向活动完成()添加动画 [英] How can I add an animation to the activity finish()

查看:32
本文介绍了如何向活动完成()添加动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在创建活动时使用 overridePendingTransition 并且效果很好,我可以看到淡入效果很好,但是当我尝试为活动的结束设置动画时,它仍然在执行默认的从右到左滑动.

I'm using overridePendingTransition for when my activity is created and that works fine I can see the fade in works great, but when I try and animate the finish on the activity it is still doing the default right to left slide.

我首先尝试在启动 Activity 时定义 out 动画,如下所示:

I first tried defining the out animation when I start the activity as follows:

Intent myIntent = new Intent(a, SkdyAlert.class);
    myIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    a.startActivity(myIntent);
    if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.DONUT) {
        AnimationHelper.overridePendingTransition(a, R.anim.fadein, R.anim.fadeout);
    }

然后当我完成活动时我也尝试这样做

Then I tried doing it when I finish the activity as well

okBtn.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            finish();
            if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.DONUT) {
                AnimationHelper.overridePendingTransition(activity, 0, R.anim.fadeout);
            }
        }
    });

但是这些方法都不会阻止退出动画的从右到左"滑动.关于我做错了什么的任何想法?

But neither of these approaches will prevent the "right to left" slide for the exit animation. Any ideas on what I'm doing wrong?

推荐答案

我在调用 finish() 后覆盖挂起的转换;

I override pending transition just after calling finish();

就我而言,我这样做是为了避免过渡.

In my case, I have done it to avoid transitions.

finish();
Details.this.overridePendingTransition(R.anim.nothing,R.anim.nothing);

顺序很重要:)

这篇关于如何向活动完成()添加动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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