다음 코드를 사용하여 조각을 사용할 때 뒤로 버튼을 누르면 시스템이 백 스택의 애니메이션을 반전시킬 것이라고 생각했습니다:
FragmentManager fm = getFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
ft.setCustomAnimations(R.anim.slide_in, R.anim.hyperspace_out);
ft.replace(R.id.viewContainer, new class(), "layout").addToBackStack(null).commit();
올바른 애니메이션 사용 저는 다음을 사용했고 마법처럼 작동합니다.
slide_in_left.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="@android:integer/config_mediumAnimTime" >
<objectAnimator
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="500"
android:propertyName="x"
android:valueFrom="1000"
android:valueTo="0"
android:valueType="floatType" />
</set>
slide_in_right.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="@android:integer/config_mediumAnimTime" >
<objectAnimator
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="500"
android:propertyName="x"
android:valueFrom="0"
android:valueTo="1000"
android:valueType="floatType" />
</set>
슬라이드_아웃_왼쪽.xml
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="@android:integer/config_mediumAnimTime" >
<objectAnimator
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="500"
android:propertyName="x"
android:valueFrom="0"
android:valueTo="-1000"
android:valueType="floatType" />
</set>
슬라이드_아웃_오른쪽.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="@android:integer/config_mediumAnimTime" >
<objectAnimator
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="500"
android:propertyName="x"
android:valueFrom="-1000"
android:valueTo="0"
android:valueType="floatType" />
</set>
그런 다음 조각을 추가하는 동안 다음을 사용합니다.
setCustomAnimations(R.anim.slide_in_left, R.anim.slide_out_left,
R.anim.slide_out_right, R.anim.slide_in_right)
그러면 100% 작동합니다.
저의 경우는
ft.setCustomAnimations(android.R.anim.slide_in_left, android.R.anim.slide_out_right,
R.anim.slide_in_right, R.anim.slide_out_left);
완벽한 애니메이션 만들 것이라고 주장했다.
<?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>
<?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>
.setCustomAnimations(R.animator.fragment_fade_in,
R.animator.fragment_fade_out,
R.animator.fragment_fade_p_in,
R.animator.fragment_fade_p_out)
위의 내용을 다음과 같이 바꿉니다:
mFragmentManager.beginTransaction()
.setCustomAnimations(R.animator.fragment_fade_in,
R.animator.fragment_fade_out,
R.animator.fragment_fade_p_in,
R.animator.fragment_fade_p_out)
.replace(R.id.main_container, FragmentPlayerInfo.getInstance(data))
.addToBackStack(FragmentPlayerInfo.TAG)
.commit();
이 작품은 가져다줄래요!! 이 코드 조각을! 이 코드를 사용하여 활동을 하려면 처음부터 삭제하시겠습니까 그레이스티비티 () ','!!
getActivity().getSupportFragmentManager()
.beginTransaction()
.setCustomAnimations(android.R.anim.slide_in_left, android.R.anim.fade_out,android.R.anim.slide_in_left, android.R.anim.fade_out)
.replace(R.id.fragment_container, new YourFragment)
.addToBackStack(null)
.commit();
당신의 행운을 빕니다!!
이는 트랜잭션까지 언급한 부분 클래스.
/**
* Set specific animation resources to run for the fragments that are
* entering and exiting in this transaction. The <code>popEnter</code>
* and <code>popExit</code> animations will be played for enter/exit
* operations specifically when popping the back stack.
*
* @param enter An animation or animator resource ID used for the enter animation on the
* view of the fragment being added or attached.
* @param exit An animation or animator resource ID used for the exit animation on the
* view of the fragment being removed or detached.
* @param popEnter An animation or animator resource ID used for the enter animation on the
* view of the fragment being readded or reattached caused by
* {@link FragmentManager#popBackStack()} or similar methods.
* @param popExit An animation or animator resource ID used for the enter animation on the
* view of the fragment being removed or detached caused by
* {@link FragmentManager#popBackStack()} or similar methods.
*/
@NonNull
public abstract FragmentTransaction setCustomAnimations(@AnimatorRes @AnimRes int enter,
@AnimatorRes @AnimRes int exit, @AnimatorRes @AnimRes int popEnter,
@AnimatorRes @AnimRes int popExit);
그래서 결국 이와 같은 방법을 사용할 수 있습니다.
mFragmentManager.beginTransaction()
.replace(R.id.container, fragment)
.setCustomAnimations(R.anim.slide_left,//enter
R.anim.slide_out_left,//exit
R.anim.slide_right,//popEnter
R.anim.slide_out_right)//popExit
.addToBackStack(fragment.toString())
.commit();