How to make a general transitional animation from ViewPager to another fragment?

I have the following situation. Activity[FragmentWithPager[PageWithGrid]]and I want to do trandition animation from list itemto DetailFragment, but I don't know if I will be wrong. I said the same transitionNameto the representations in models list itemand fragment detailtry to do animatiot transition to the following code.

val fragmentTransaction = supportFragmentManager.beginTransaction()
transitionItems.forEach { view ->
    fragmentTransaction.addSharedElement(view, view.transitionName)
}

val fragment = DetailFragment()
val transitionSet = TransitionSet().apply {
     addTransition(ChangeTransform())
     addTransition(ChangeClipBounds())
     addTransition(ChangeBounds())
}
fragment.sharedElementEnterTransition = transitionSet
fragment.sharedElementReturnTransition = transitionSet

fragmentTransaction.replace(R.id.root, fragment)
fragmentTransaction.addToBackStack(null)
fragmentTransaction.commit()
+4
source share
4 answers

I found what I did wrong. The transition name must be unique for each element in the list and page if you switch a fragment with a pager . The animation started working when I added a page and list index for each transition name.

+3

API undefined. , . , :

GridFragment ViewPagerFragment Fragment :

Activity[ViewPagerFragment[ContainerFragment[GridFragment]]]

, .

my github repo

+2

-

  • .
  • xml
  • SharedElement , .

you can find link 1 , 2 , 3

+1
source

I found this google sample, it is very useful and it handles fragments very nicely google transition sample

hope this helps u

0
source

Source: https://habr.com/ru/post/1695313/


All Articles