简体   繁体   English

"带有动画的打开和关闭活动在后按时不起作用但在打开时起作用"

[英]Opening and closing activity with animation not working on back pressed but working for opening

I am developing an Android app.我正在开发一个 Android 应用程序。 In my app, I am opening an activity with animation (sliding left to right).在我的应用程序中,我正在打开一个带有动画的活动(从左向右滑动)。 I also want it close sliding right to left on back pressed.我还希望它在背面按下时从右向左滑动。 But Animation only working on activity open.但动画仅适用于活动开放。 Not working on close.不关闭工作。 It just closes normally without slide animation.它只是正常关闭而没有幻灯片动画。

Here is my code:这是我的代码:

slide_in.xml幻灯片输入.xml

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

slide_out.xml幻灯片输出.xml

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

Inside onCreate of second activity第二个活动的 onCreate 内部

 overridePendingTransition(R.anim.slide_in, R.anim.slide_out);

But it is only working for opening activity.但它仅适用于开放活动。 Animation not working for closing activity.动画不适用于关闭活动。 What is missing or wrong with my code?我的代码有什么遗漏或错误? How can I get it work on closing activity?我怎样才能让它在关闭活动中起作用?

尝试在您的startActivity方法之后调用overridePendingTransition

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM