32

I have a TextView in my activity A. How can I make shared element transition of TextView from activity A and a title of CollapsingToolbarLayout.setTitle() from activity B?

Is there way to obtain its title view id from CollapsingToolbarLayout's source code?

Thanks for help!

Augusent
  • 589
  • 7
  • 10
  • In theory you could nest a dummy TextView with exactly the same position, color and size inside your CollapsingToolbarLayout. Then just after the transition end you hide it and that will make the illusion. But I had problems with the correct positioning inside CollapsingToolbarLayout relative to the bottom. It was always was somewhat incorrect. – WindRider Oct 30 '15 at 16:46
  • 4
    @WindRider Yes, I almost achieve this effect with same way. But better solution is not to use embedded title in collapsing layout but create own TextView title with coordinator behavior like here: https://github.com/saulmm/CoordinatorBehaviorExample and easily use it with shared element transitions. – Augusent Oct 30 '15 at 18:01
  • 10x for the good advice and the example! – WindRider Nov 02 '15 at 12:10

2 Answers2

3

I've had similar issue. My app had CollapsingToolbar which had image in it and I wanted to share the image which was going from normal ListView into the CollapsingToolbar.

You need to create a custom TextView and use it as a replacement of the actual title in CollapsingToolbar. Also need to set the actual title to empty string so it looks hidden.

You should look into this answer where its shown how to use custom view in CollapsingToolbar with the listener which is needed to replicate animations of normal title. It may not look identical but I can't think of better idea. Hope it was helpful.

Community
  • 1
  • 1
Bartando
  • 719
  • 8
  • 26
2

You can just use the collapsing tool bar as the target of the animation and it looks ok, but also animates the back button or drawer indicator which may not be what you want.

Tyler Pfaff
  • 4,900
  • 9
  • 47
  • 62