2017-09-19 13 views
0

フラグメント間のアニメーションが必要です。 2番目のフラグメントは右下からスライドし、最初のフラグメント(現行のフラグメントはそのままの状態にします)がFABボタンをクリックすると発生します。フラグメント間のアニメーション

私が試したこと。

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> 

問題は、私は実際にスライド私がここで見逃している何 見ることができないと思っているのですか?

+1

https://stackoverflow.com/questions/4932462/animate-the-transition-between-fragmentsを参照してください。 –

答えて

0

最初のフラグメントをそのまま保持したい場合は、最初のフラグメントのアニメーションリソースを定義する必要はありません。

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

私はちょうど100% x and y to 0% x and yから完全にビューを変換するために、あなたのslide_in_from_bottom_right.xmlを更新しました。

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

また、ときに戻って2番目のフラグメントからの最初のフラグメントへの第2のフラグメントのためのポップ・アニメーションを設定することができます。

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> 
関連する問題