How to use shared element transitions in Navigation Controller

前端 未结 9 546
醉话见心
醉话见心 2021-01-31 08:06

I would like to add a shared elements transition using the navigation architecture components, when navigating to an other fragment. But I have no idea how. Also in the document

9条回答
  •  广开言路
    2021-01-31 08:45

    FirstFragment

    val extras = FragmentNavigatorExtras(
        imageView to "secondTransitionName")
    view.findNavController().navigate(R.id.confirmationAction,
        null, // Bundle of args
        null, // NavOptions
        extras)
    

    first_fragment.xml

    
    

    SecondFragment

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
                              savedInstanceState: Bundle?): View {
        sharedElementEnterTransition = ChangeBounds().apply {
            duration = 750
        }
        sharedElementReturnTransition= ChangeBounds().apply {
            duration = 750
        }
        return inflater.inflate(R.layout.second_fragment, container, false)
    }
    

    second_fragment.xml

    
    

    I tested it. It is worked.

提交回复
热议问题