0

I'm trying to animate transitions between Activities in my application. I have right_to_left.xml which is working on Portrait screen orientation.

Here is right_to_left.xml

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

Here is right_to_left_slide_out.xml (to slide out previous activity on transition.)

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

I was using it after startActivity() and there was no problem on Portrait mode.

But I added an option to change screen orientation to Landscape mode.

If landscape mode is enabled, I set requested orientation with code below in onCreate().

//SCREEN ORIENTATION
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

This works well, activity is created in Landscape mode without any issue. But when I try to start activity with overridePendingTransition(R.anim.right_to_left, R.anim.right_to_left_slide_out) which is working on Portrait mode, no transition animation seems on Landscape mode.

Is there something I've missed?

EDIT: I've tried to create a new animation xml file that works with YDelta. It didn't work either.

Emre Alparslan
  • 1,022
  • 1
  • 18
  • 30

1 Answers1

1

The animation is not playing because android studio doesn't render views that are not set to Visible or Invisible when the app starts. The problem is that your landscape view is not already rendered when the animation starts playing. It renders it on the spot and skips the animation entirely.

To test this theory, simply add to your activity a version of your landscape layout with < include > and set it to invisible. Then run the app. See if the animation plays. If it does, then this theory is correct and we can try to figure out a solution.

Good luck.

Luís Henriques
  • 604
  • 1
  • 10
  • 30