백스택에서 프래그먼트 애니메이션을 리버스하는 방법은 무엇인가요?

다음 코드를 사용하여 조각을 사용할 때 뒤로 버튼을 누르면 시스템이 백 스택의 애니메이션을 반전시킬 것이라고 생각했습니다:

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();
해결책

커스텀 애니메이션에 대한 안드로이드 문서]1에 따르면:

변경:

ft.setCustomAnimations(R.anim.slide_in, R.anim.hyperspace_out);

To:

ft.setCustomAnimations(R.anim.slide_in, R.anim.hyperspace_out, R.anim.hyperspace_in, R.anim.slide_out );

이제 백스택이 역방향으로 움직입니다!!

해설 (3)

올바른 애니메이션 사용 저는 다음을 사용했고 마법처럼 작동합니다.

slide_in_left.xml

<?xml version="1.0" encoding="utf-8"?>


slide_in_right.xml

 <?xml version="1.0" encoding="utf-8"?>




슬라이드_아웃_왼쪽.xml





슬라이드_아웃_오른쪽.xml

<?xml version="1.0" encoding="utf-8"?>




그런 다음 조각을 추가하는 동안 다음을 사용합니다.

setCustomAnimations(R.anim.slide_in_left, R.anim.slide_out_left,
                                R.anim.slide_out_right, R.anim.slide_in_right)

그러면 100% 작동합니다.

해설 (4)

저의 경우는

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

완벽한 애니메이션 만들 것이라고 주장했다.

  • slide_in_right *
<?xml version="1.0" encoding="utf-8"?>



  • slide_out_left *
<?xml version="1.0" encoding="utf-8"?>



해설 (0)
.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();
해설 (3)

이 작품은 가져다줄래요!! 이 코드 조각을! 이 코드를 사용하여 활동을 하려면 처음부터 삭제하시겠습니까 그레이스티비티 () ','!!

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();

당신의 행운을 빕니다!!

해설 (0)

이는 트랜잭션까지 언급한 부분 클래스.

/**
     * 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();
해설 (0)