简体   繁体   English

overridePendingTransition在Android中不起作用

[英]overridePendingTransition not working in Android

The following code is not working for me. 以下代码对我不起作用。

finish();
overridePendingTransition(R.anim.slide_up,R.anim.slide_up);
startActivity(intent);
overridePendingTransition(R.anim.slide_up,R.anim.slide_up);

and the XML for animation is 而动画的XML是

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromXDelta="50%p" android:toXDelta="-50"
        android:duration="@android:integer/config_mediumAnimTime"/>
<alpha android:fromAlpha="0.0" android:toAlpha="1.0"
        android:duration="@android:integer/config_mediumAnimTime" />
</set>

I searched the web, saw all the threads from Stack Overflow, but not able to fix this. 我搜索了网络,看到Stack Overflow中的所有线程,但无法修复此问题。

I made it work out in the following way. 我用以下方式解决了这个问题。

I have removed the 我已经删除了

overridePendingTransition(R.anim.slide_up,R.anim.slide_up);

from the above code and placed it in onPause() , and it worked like a charm. 从上面的代码中将它放在onPause() ,它就像一个魅力。

Sometimes animations are disabled on the phone. 有时在手机上禁用动画。 To check go to settings > display > animation > allow "all animations". 要检查转到设置>显示>动画>允许“所有动画”。 This will allow overridePendingTransition to work properly if it was disabled. 这将允许overridePendingTransition在禁用时正常工作。

If you activate usb debugging mode, it can disable the transitions effects. 如果激活USB调试模式,它可以禁用转换效果。 Enter Developer options (where you activated debugging mode), find the user's interface section, check if the animation's transition scale have the animations disabled. 输入开发人员选项(激活调试模式的位置),找到用户的界面部分,检查动画的过渡比例是否禁用了动画。 If so, set it to .5x. 如果是这样,请将其设置为.5x。 Done! 完成!

在finish()之前尝试startActivity

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

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