2017-09-19 2 views
0

Ich möchte Animation zwischen Fragmenten. Das zweite Fragment sollte von rechts unten herausrutschen und das erste (aktuelles Fragment sollte so bleiben wie es ist) sollte beim Klick auf eine FAB-Taste passieren.Animation zwischen Fragmenten

Was ich versucht habe.

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> 

Das Problem ist, dass ich nicht in der Lage bin die eigentliche Gleiten in sehen Was ich hier verpasst haben.?

+1

siehe https://stackoverflow.com/questions/4932462/animate-the-transition-between-fragments –

Antwort

0

Wenn Sie das erste Fragment beibehalten möchten, müssen Sie keine Animationsressource für das erste Fragment definieren.

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

ich gerade aktualisiert Ihre slide_in_from_bottom_right.xml die Sicht perfekt aus 100% x and y to 0% x and y zu übersetzen.

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" 
/> 

Sie auch die Pop-Animation für das zweite Fragment festlegen können Sie, wenn auf das erste Fragment aus dem zweiten Fragment zurück.

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> 
Verwandte Themen