본문 바로가기

Mobile/Android

[ Android ] 쉽게 정리한 Fragment 애니메이션

반응형
반응형

Fragment animation

 

//class 파일

public void animReplaceFragment(Fragment fragment) {
    FragmentManager fm = getSupportFragmentManager();
    FragmentTransaction ft = fm.beginTransaction();
    ft.setCustomAnimations(
    	R.anim.enter_from_right, 
        R.anim.exit_to_right, 
        R.anim.enter_from_right, 
        R.anim.exit_to_right);
    ft.addToBackStack(null);
    ft.replace(R.id.main_container, fragment);
    ft.commit();
}



// xml 파일
res/anim 생성
1) enter_from_right.xml

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



2) exit_to_right.xml

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



반응형