fragment替换动画的实现

    xiaoxiao2021-04-02  41

    右进动画slide_right_in.xml:

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

    <set xmlns:android="http://schemas.android.com/apk/res/android" 

    android:fillAfter="true">   

    <translate  

    android:duration="300"  

    android:fromXDelta="100%p"  

    android:toXDelta="0"/>  

    </set> 

    左出动画slide_left_out.xml:

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

    <set xmlns:android="http://schemas.android.com/apk/res/android">  

    <translate   android:duration="300"   android:fromXDelta="0"   android:toXDelta="-100%p" />   </set>  

    fragment切换:

    FragmentManager fragmentManager = getSupportFragmentManager();  

    FragmentB frgB=new FragmentB();  

    FragmentTransaction transaction = fragmentManager.beginTransaction(); 

    transaction.setCustomAnimations(R.anim.slide_right_in,R.anim.slide_left_out);  

    transaction.replace(containerId,fraB);  

    transaction.commit(); 

    转载请注明原文地址: https://ju.6miu.com/read-665855.html

    最新回复(0)