How to use shared element transitions in Navigation Controller

前端 未结 9 519
醉话见心
醉话见心 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:51

    I took reference from this github sample https://github.com/serbelga/android_navigation_shared_elements

    cardView.setOnClickListener{
      val extras = FragmentNavigatorExtras(
        imageView to "imageView"
      )
      findNavController().navigate(R.id.detailAction, null, null, extras)
    }
    
    override fun onCreate(savedInstanceState: Bundle?) {
      super.onCreate(savedInstanceState)
      sharedElementEnterTransition = TransitionInflater.from(context).inflateTransition(android.R.transition.move)
    

    It is working properly.

提交回复
热议问题