1. 程式人生 > >Fragment切換動畫

Fragment切換動畫

Fragment切換動畫


FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
//**************方法一,使用系統已定義動畫***************
// ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);//各個屬性含義請看FragmentTransaction中原始碼
//**************方法二,使用自定義動畫********************
ft.setCustomAnimations(R.anim.slide_in_alpha
, R.anim.slide_out_alpha); ft.replace(containerViewId, newFragment).commit();
 
 
 
 
**********slide_in_alpha***********

 
<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="400"
    android:fromAlpha="0"
    android:interpolator=
"@android:anim/decelerate_interpolator" android:toAlpha="1" />

 
*************
 slide_out_alpha
 ************* 
 

 
<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="400"
    android:fromAlpha="1"
    android:interpolator=
"@android:anim/decelerate_interpolator" android:toAlpha="0" />