老questiion,你可能已經想通了,但是對於未來的參考:
這裏是你用什麼來設置自定義動畫,當你通過代碼替換片段:
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.setCustomAnimations(R.anim.slide_in_left, R.anim.slide_out_right);
ft.replace(R.id.fragment_container, newFragment, "fragment");
// Start the animated transition.
ft.commit();
這裏是一個slide_in_left動畫的示例:
<?xml version="1.0" encoding="utf-8"?>
<set>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXDelta="-100%"
android:toXDelta="0"
android:interpolator="@android:anim/decelerate_interpolator"
android:duration="500"/>
</set>
請注意,如果您正在使用兼容性庫,則爲動畫。相反,如果你正在使用和SDK與該FragmentManager的原生支持,然後你的動畫看起來就像這樣:
<?xml version="1.0" encoding="utf-8"?>
<set>
<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
android:propertyName="x"
android:valueType="floatType"
android:valueFrom="-1280"
android:valueTo="0"
android:duration="500"/>
</set>
這是因爲兼容性庫不支持新的objectAnimator類型,而是隻實現舊的動畫框架。
[Animate the fragments between transition]的可能重複(http://stackoverflow.com/questions/4932462/animate-the-transition-between-fragments) – TalkLittle 2014-07-09 20:57:43