Fragment transaction animation: slide in and slide out

前端 未结 6 1455
梦谈多话
梦谈多话 2020-11-27 09:44

I\'ve check some tutorials for animate transaction between fragments. I\'ve used this method for animation and it works:

fragmentTransaction.setCustomAnimatio         


        
6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-27 10:19

    There is three way to transaction animation in fragment.

    Transitions

    So need to use one of the built-in Transitions, use the setTranstion() method:

    getSupportFragmentManager()
            .beginTransaction()
            .setTransition( FragmentTransaction.TRANSIT_FRAGMENT_OPEN )
            .show( m_topFragment )
            .commit()
    

    Custom Animations

    You can also customize the animation by using the setCustomAnimations() method:

    getSupportFragmentManager()
            .beginTransaction()
            .setCustomAnimations( R.anim.slide_up, 0, 0, R.anim.slide_down)
            .show( m_topFragment )
            .commit()
    

    slide_up.xml

    
    
    

    slide_down.xml

    
    
    

    Multiple Animations

    Finally, It's also possible to kick-off multiple fragment animations in a single transaction. This allows for a pretty cool effect where one fragment is sliding up and the other slides down at the same time:

    getSupportFragmentManager()
            .beginTransaction()
            .setCustomAnimations( R.anim.abc_slide_in_top, R.anim.abc_slide_out_top ) // Top Fragment Animation
            .show( m_topFragment )
            .setCustomAnimations( R.anim.abc_slide_in_bottom, R.anim.abc_slide_out_bottom ) // Bottom Fragment Animation
            .show( m_bottomFragment )
            .commit()
    

    To more detail you can visit URL

    Note:- You can check animation according to your requirement because above may be have issue.

提交回复
热议问题