2021-01-25-Android-Navigation-Animation

Create following files under app/src/main/res/anim/ directory

slide_in_left.xml

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

slide_in_right.xml

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

slide_out_left.xml

slide_out_right.xml

Apply animation

  • Open navigation.xml unde app/src/main/res/navigation

  • Select the fragment-navigation-action, apply animation using IDE or xml should be as follows.

In this example, it's from home fragment to about fragment.

Last updated

Was this helpful?