3

Edit

Issue can be seen here:

enter image description here

I have a login screen and a registration screen.

When the user clicks the registration button - I would like to slide from the login screen to the registration screen. I have this working okay.

When the user presses the back button on the registration screen, I would like to slide back to the login screen.

This appears to be working, but the login screen activity is loading in the old activity before the animation has completed.

LoginActivity.java

public void createAccount(View view) {
    Log.d(TAG, "Create Account clicked");
    Intent intent = new Intent(getApplicationContext(), SignupActivity.class);
    startActivityForResult(intent, REQUEST_SIGNUP);
    overridePendingTransition(R.anim.push_left_in, R.anim.push_left_out);
}

RegisterActivity.java

@Override
public void onBackPressed() {
    super.onBackPressed();
    Log.d(TAG, "Back clicked - return to login");
    finish();
    overridePendingTransition(R.anim.push_right_in, R.anim.push_right_out);
}

push_left_in.xml

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

push_left_out.xml

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

push_right_in.xml

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

push_right_out.xml

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

Note

I have tried both the solutions below and neither works in my case.

overridePendingTransition shows second activity too quickly

TomSelleck
  • 6,706
  • 22
  • 82
  • 151
  • Can downvoter explain reasoning? – TomSelleck Jan 25 '18 at 17:29
  • What is the animation supposed to be when the user goes back? – dazza5000 Jan 28 '18 at 16:16
  • So when the user clicks "Create Account" on the first screen, the Register activity should pull from right to left. When the user clicks back - the Login screen should pull from left to right - the reverse of the first animation. – TomSelleck Jan 28 '18 at 17:30

1 Answers1

3

push_right_in.xml and push_right_out.xml seem to be mixed up.

push_right_in.xml should be starting off screen: android:fromXDelta="-100%p" and be finishing on screen: android:toXDelta="0"

push_right_out.xml should be starting on screen: android:fromXDelta="0" and finishing off screen: android:toXDelta="100%p".

carlmango11
  • 525
  • 5
  • 19