Animation cuts fragment during transition animation between fragments

Viewed 85

I have a SignInFragment. When "Sign up here" is clicked, SignUpFragment replace SignInfragment with slide animation, but SignIn is added to stack so when back is pressed, it returns to SignInFragment instead of closing activity.

There is a problem when slide back animation is run. It happens because first fragment is shorter than the second fragment, but I don't know how to fix it.

Here is a step by step on how the problem happens:

SignInFragment: Click on "Sign up here"

Slide animation between SignInFragment and SignUpFragment working fine

SignUpFragment: Click on back button

Slide animation between SignUpFragment and SignInFragment NOT working fine

As you can see, SignUpFragment is cutted to fix SignInFragment height during animation, how can I fix that so animation shows everything from the longer fragment?

"Sign in here" code:

//Get inflator view to modify it before returning
val signinfragment: View = inflater.inflate(R.layout.fragment_sign_up, container, false)

//Get activity instance that called this fragment
val superActivity = (activity as AppCompatActivity?)!!

//Set 'Sign up here' on click action
signinfragment.tv_sign_up.setOnClickListener {
    //Create fragment transaction to inflate a new fragment that will replace this one
    var transaction = superActivity.supportFragmentManager.beginTransaction()

    //New fragment will be added to back stack so when user clicks back, it will return to
    //this fragment instead of closing activity
    transaction.addToBackStack(null)

    //Set slide animation from this fragment to new one (right slide animation) and from
    //that one to this one (left slide animation) during back action
    transaction.setCustomAnimations(R.anim.slide_in_right, R.anim.slide_out_left, R.anim.slide_in_left, R.anim.slide_out_right)

    transaction.replace(R.id.container, SignUpFragment()).commit()
}

Animations code: slide_in_right:

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

slide_out_left:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate
        android:duration="@android:integer/config_mediumAnimTime"

    android:fromXDelta="0"
    android:toXDelta="-100%p" />
</set>

slide_in_left:

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

slide_out_right:

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