我想要使用FragmentTransaction.setCustomAnimations實現以下效果。FragmentTransaction動畫滑過頂部
- 片段A是顯示
- 替換片段A與片段B片段A的更換期間應保持可見。片段B應該從右側滑入。片段B應該在片段A的頂部滑動。
我沒有問題在動畫設置中獲取幻燈片。我的問題是,我無法弄清楚如何使片段A保持原狀,並且在動畫中的幻燈片正在運行時處於片段B下。無論我做什麼,似乎碎片A都是頂級的。
我該如何做到這一點?
這裏是FragmentTransaction代碼:
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.setCustomAnimations(R.anim.slide_in_right, R.anim.nothing, R.anim.nothing,
R.anim.slide_out_right);
ft.replace(R.id.fragment_content, fragment, name);
ft.addToBackStack(name);
ft.commit();
正如你可以看到我已經定義了一個動畫R.anim.nothing爲「走出去」的動畫,因爲我其實不想片段A做任何其他而不僅僅是在交易過程中保持它的位置。
這裏是動畫資源:
slide_in_right.xml
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="@android:integer/config_mediumAnimTime"
android:fromXDelta="100%p"
android:toXDelta="0"
android:zAdjustment="top" />
nothing.xml
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="@android:integer/config_mediumAnimTime"
android:fromAlpha="1.0"
android:toAlpha="1.0"
android:zAdjustment="bottom" />
我已經提交了一個錯誤報告,因爲當前的Z排序是錯誤的。 https://code.google.com/p/android/issues/detail?id=163384&thanks=163384&ts=1428443402 – sbaar