简体   繁体   English

Android OverridePendingTransition()无法正常工作

[英]Android overridePendingTransition() not working

I am trying to animate the transition between two Activities with a simple fade animation . 我正在尝试使用简单的淡入淡出动画为两个活动之间的过渡设置动画

When I use the standard android animations it works fine, but when I define my own animations, despite them being the exact same thing, it does not work and i don't see a transition. 当我使用标准的android动画时,效果很好,但是当我定义自己的动画时,尽管它们是完全一样的东西,但它不起作用,也看不到过渡。

Working code 工作代码

Method call 方法调用

((Activity) context).overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);

Android animation (fade_in.xml) Android动画 (fade_in.xml)

<alpha xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@interpolator/decelerate_quad"
    android:fromAlpha="0.0" android:toAlpha="1.0"
    android:duration="@android:integer/config_longAnimTime" />

Non working code 非工作代码

Method call 方法调用

((Activity) context).overridePendingTransition(R.anim.activity_fade_in, R.anim.activity_fade_out);

Custom animation (res/anim/activity_fade_in.xml) 自定义动画 (res / anim / activity_fade_in.xml)

<alpha xmlns:android="http://schemas.android.com/apk/res/android"
   android:duration="500"
   android:fromAlpha="0.0"
   android:interpolator="@android:interpolator/decelerate_quad"
   android:toAlpha="1.0"/>

Change your code this way 以此方式更改代码

<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/bounce_interpolator" >
      <alpha xmlns:android="http://schemas.android.com/apk/res/android"
            android:duration="500"
            android:fromAlpha="0.0"
            android:interpolator="@android:interpolator/decelerate_quad"
            android:toAlpha="1.0"/>
</set>

For some reason, unplugging my test device and coming back an hour later seems to have resolved the issue. 出于某种原因,拔掉测试设备的电源并在一个小时后回来似乎已解决了该问题。 I'm not quite sure what happened but everything seems to be working properly now. 我不太确定发生了什么,但是现在一切似乎都可以正常工作。

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

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