fragment替换动画的实现

来源:互联网 发布:无线路由器推荐 知乎 编辑:程序博客网 时间:2024/05/22 03:42

右进动画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(); 



0 0