Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NavigationGraph animation not working issue Android

I am using this code with NavigationGraph Fragment

 <fragment
        android:id="@+id/editProfileFragment"
        android:name="com.uvm.ui.editprofile.EditProfileFragment"
        android:label="FragmentFour"
        tools:layout="@layout/edit_fragment_profile" >
        <action
            app:popExitAnim="@anim/nav_default_pop_exit_anim"
            app:exitAnim="@anim/nav_default_exit_anim"
            app:enterAnim="@anim/nav_default_enter_anim"
            app:popEnterAnim="@anim/nav_default_pop_enter_anim"
            android:id="@+id/action_editProfileFragment_to_profileFragment"
            app:destination="@id/profileFragment"  />
    </fragment>

and then

navController.navigate(R.id.editProfileFragment);

using for navigation of fragment. its working fine and fragment replace as well but enterAnim, exitAnim etc properties not working. fragment replacing without animation. how could i resolved this? one more query is that is NavigationGraph replace fragment or add fragment? and how could i get total count of stack?

like image 412
aj0822ArpitJoshi Avatar asked Dec 28 '18 06:12

aj0822ArpitJoshi


People also ask

Is animation possible on Android?

On Android 4.4 (API level 19) and higher, you can use the transition framework to create animations when you swap the layout within the current activity or fragment. All you need to do is specify the starting and ending layout, and what type of animation you want to use.

How do I set up animator on Android?

Navigate to the app > res > Right-Click on res >> New >> Directory >> Name your directory as “anim”. Inside this directory, we will create our animations. For creating a new anim right click on the anim directory >> Animation Resource file and give the name to your file.


1 Answers

As i can see you are using RID of Fragment to navigate while to apply transaction animation you are giving all the animation's in the action's.

<action
            app:popExitAnim="@anim/nav_default_pop_exit_anim"
            app:exitAnim="@anim/nav_default_exit_anim"
            app:enterAnim="@anim/nav_default_enter_anim"
            app:popEnterAnim="@anim/nav_default_pop_enter_anim"
            android:id="@+id/action_editProfileFragment_to_profileFragment"
            app:destination="@id/profileFragment"  />

So, to apply animation's use RID of action to navigate.

navController.navigate(R.id.action_editProfileFragment_to_profileFragment);

By default Navigation Component use Replace Fragment Transaction's.

And how could i get total count of stack?

currently i have not found a way to get this count what is your use case her can you explain?

This should work.

like image 90
Anmol Avatar answered Oct 08 '22 19:10

Anmol