Reputation:
I just discovered the android overrivePendingTransition() method. It works fine but I have the following problem :
In the Settings/Dislpay menu, you can choose to show no animations, some animations or all animations, and the method only works when it is set to all animations.
Can I bypass that ?
Upvotes: 4
Views: 2466
Reputation: 701
overridePendingTransition
Deprecation in AndroidThe overridePendingTransition
method is deprecated in Android. Below are some alternatives using the Transition framework and custom animations:
val i = Intent(this@MainActivity, ReferActivity::class.java)
val options = ActivityOptions.makeSceneTransitionAnimation(this).toBundle()
startActivity(i, options)
val i = Intent(this@MainActivity, ReferActivity::class.java)
val options = ActivityOptions.makeCustomAnimation(this, R.anim.enter_anim, R.anim.exit_anim).toBundle()
startActivity(i, options)
Example enter_anim.xml
for Slide-in Animation from Right to Left:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="100%"
android:toXDelta="0%"
android:duration="300" />
</set>
Example exit_anim.xml
for Slide-out Animation to the Right:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="0%"
android:toXDelta="100%"
android:duration="300" />
</set>
res/anim
directory.Upvotes: 0
Reputation: 30794
The settings you're talking about are user preferences. If one of your users wanted to turn off all animations, why would you want to find a workaround to continue showing animations in your app? It doesn't seem very user-friendly.
At any rate, overridePendingTransition
is used to animate between Activities
, as opposed to Views
which is part of why you can turn them off, and was introduced in Android 2.0. There isn't another SDK method available that does the same thing; however, you can try using a LayoutAnimation
to animate the layout you provide for each Activity
you're creating. It wouldn't be exactly the same as overridePendingTransition
, but I think it's going to be one of the closest things you'll find to an alternative.
your_animation.xml:
<layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android"
android:animation="@anim/THE_ANIMATION_YOU_WANT_TO_USE" />
your_layout.xml:
android:layoutAnimation="@anim/your_animation"
Upvotes: 3