Android pop fragment from backstack with animation

前端 未结 3 1151
天命终不由人
天命终不由人 2021-02-19 04:52

I have an activity that loads a Fragment A in it. Fragment A contains ListView and when clicking on list item I load another Fragment B in place of Fragment A to show the listvi

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-19 05:17

    In my case

    FragmentTransaction ft = getFragmentManager().beginTransaction();
            ft.setCustomAnimations(android.R.anim.slide_in_left, 
                                   android.R.anim.slide_out_right, 
                                   R.anim.slide_in_right,
                                   R.anim.slide_out_left);
            ft.replace(R.id.fragment_container, targetFragment).addToBackStack(null).commit();
    

    this line

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

    would create perfect animation.

    slide_in_right

    
    
        
        
    
    

    slide_out_left

    
    
        
        
    
    

提交回复
热议问题