如何使用customAnimation

问题描述 投票:0回答:1

我一直在互联网上搜索,每次我得到相同的结果,我想设置一个自定义动画到我的片段,检查以下代码:FragmentManager fragmentManager = getFragmentManager();

    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    fragmentTransaction.setCustomAnimations(R.anim.slide_in_right);
    SpeedMatchFragment speedMatchFragment = new SpeedMatchFragment();
    fragmentTransaction.replace(R.id.fragment_container,speedMatchFragment);
    fragmentTransaction.addToBackStack(null);
    fragmentTransaction.commit();

但这里的fragmentTransaction.setCustomAnimations(R.anim.slide_in_right);我得到无法解决错误!请注意,我已经将anim文件夹设为xml ...并且所有内容都需要完成!这是xml代码:

<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="@android:integer/config_mediumAnimTime"/>

android animation fragment
1个回答
0
投票

根据我的理解,你必须设置进入和退出动画,然后错误就像魔术......

 FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
     fragmentTransaction.setCustomAnimations(R.anim.pop_enter, R.anim.pop_exit);
        SpeedMatchFragment speedMatchFragment = new SpeedMatchFragment();
        fragmentTransaction.replace(R.id.fragment_container,speedMatchFragment);
        fragmentTransaction.addToBackStack(null);
        fragmentTransaction.commit();
© www.soinside.com 2019 - 2024. All rights reserved.