从animation背后的Androidstream行片段

我有一个活动,在其中加载一个片段A. 片段A包含ListView,当单击列表项目时,我加载另一片段B代替片段A来显示列表视图项目的详细信息。 在button单击并按设备后退button我加载前一个片段,它是显示ListView的片段A. 所有这一切工作正常,但我想加载片段Aanimation上后压或button单击。 我这样做,但不工作:

FragmentManager fsm = getSupportFragmentManager(); FragmentTransaction ftransaction = fsm.beginTransaction(); ftransaction.setCustomAnimations(R.anim.enter_from_left, R.anim.enter_from_left); fsm.popBackStack(); ftransaction.commit(); <?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="false" > <translate android:duration="700" android:fromXDelta="-100%" android:fromYDelta="0%" android:toXDelta="0%" android:toYDelta="0%" /> </set> <?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="false" > <translate android:duration="700" android:fromXDelta="-100%" android:fromYDelta="0%" android:toXDelta="0%" android:toYDelta="0%" /> </set> 

Solutions Collecting From Web of "从animation背后的Androidstream行片段"

如果你想要背部animation,你需要使用:

setCustomAnimations(int enter,int exit,int popEnter,int popExit)

就像是:

 setCustomAnimations(R.anim.enter_from_left, R.anim.enter_from_left, R.anim.exit_to_left, R.anim.exit_to_left); 

在我的情况

 FragmentTransaction ft = getFragmentManager().beginTransaction(); ft.setCustomAnimations(android.R.anim.slide_in_left, android.R.anim.slide_out_right, R.anim.slide_in_right, R.anim.slide_out_left); ft.replace(R.id.fragment_container, targetFragment).addToBackStack(null).commit(); 

这条线

 ft.setCustomAnimations(android.R.anim.slide_in_left, android.R.anim.slide_out_right, R.anim.slide_in_right, R.anim.slide_out_left); 

会创造完美的animation。

slide_in_right

 <?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:fromXDelta="50%p" android:toXDelta="0" android:duration="@android:integer/config_mediumAnimTime"/> <alpha android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="@android:integer/config_mediumAnimTime" /> </set> 

slide_out_left

 <?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:fromXDelta="0" android:toXDelta="-50%p" android:duration="@android:integer/config_mediumAnimTime"/> <alpha android:fromAlpha="1.0" android:toAlpha="0.0" android:duration="@android:integer/config_mediumAnimTime" /> </set>