2017-09-19 2 views
0

Je veux une animation entre les fragments. Le deuxième fragment devrait sortir de la partie inférieure droite et le premier (le fragment actuel devrait rester tel quel) cela devrait se produire au clic d'un bouton FAB.Animation entre fragments

Ce que j'ai essayé.

ft.setCustomAnimations(R.anim.slide_in_from_bottom_right,R.anim.stay); 

       ft.replace(R.id.sample_content_fragment, fragment, "XYZ"); 
       ft.addToBackStack("XYZ"); 
       Bundle bundle = new Bundle(); 

       fragment.setArguments(bundle); 
       ft.commit(); 

slide_in_from_bottom_right.xml: -

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

stay.xml: -

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

Le problème est que je ne suis pas en mesure de voir le glissement réel dans Qu'ai-je manqué ici.?

+1

s'il vous plaît se référer https://stackoverflow.com/questions/4932462/animate-the-transition-between-fragments –

Répondre

0

Si vous souhaitez conserver le premier fragment tel quel, vous n'avez pas besoin de définir la ressource d'animation pour le premier fragment.

ft.setCustomAnimations(R.anim.slide_in_from_bottom_right,0); 

Je viens mis à jour votre slide_in_from_bottom_right.xml pour traduire le point de vue parfaitement de 100% x and y to 0% x and y.

slide_in_from_bottom_right.xml

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

Vous pouvez également définir l'animation pop pour le second fragment lors de la sauvegarde du second fragment au premier fragment.

ft.setCustomAnimations(R.anim.slide_in_from_bottom_right,0,0,R.anim.pop_slide_in_from_top_left.xml); 

pop_slide_in_from_top_left.xml

<set xmlns:android="http://schemas.android.com/apk/res/android" 
    android:duration="600"> 

<translate xmlns:android="http://schemas.android.com/apk/res/android" 
    android:duration="600" 
    android:fromXDelta="0%p" 
    android:fromYDelta="0%p" 
    android:interpolator="@android:anim/accelerate_interpolator" 
    android:toXDelta="100%p" 
    android:toYDelta="100%p" /> 
</set>