How to include an unattached View in the activity transition?

Viewed 156

I draw a View that is not attached to any parent.

It's a decoration for a RecyclerView. The view sticks to the bottom and disappears when its counter part comes up in the list.

All this works fine but:

When i leave the activity the View doesn't fade with the rest of the views in the activity's transition.

It stays until the end of the animation and then disappears immediately.

( see large green view in the demo )

How do i include this unattached View in the activity's exit transition?


I've create a minimal Android Studio Project to replicate the issue: https://github.com/Ostkontentitan/transition-issue-demo

(To better see the issue possibly set your phones animation scale to >= 5)


Here is a demo:

2 Answers

Add transitionName to xml layout for the RecyclerView.

The transition animation you see is because of ActivityOptions.makeSceneTransitionAnimation(this@ItemListActivity) and if you add transitionName to the view, it works fine.

enter image description here

Not-too-educated guess

(because I haven't tried and I haven't used Transition Framework in a few months)

The way TF (Transition Framework) works is by computing the start/end values of the transition and performing the animations needed to achieve this.

RecyclerView decorations are not "views" that are part of the layout, so TF has no idea that thing exists. It does know about your RecyclerView of course, because it's contained in the ViewGroup that is animated.

You may have already know this, but in any case, what I think I'd try to do here, is create a custom transition framework transition (they are not hard to do, you can even check TransitionEverywhere and look at how that library implements some missing transitions in the framework); in your CustomTransition, you can then try to interpolate the animation values so the recycler view can redecorate as the animation progresses (like an alpha value that is animated, your custom decorator would "paint" using said alpha).

Now... in truth, I've had to do something similar once, where a custom transition was "driving" a few external views (for reasons at the time) :) but... it was not a RecyclerView item decoration, mine were just "views", so I'm not sure if you can do this this way w/a decoration.

I think it's worth trying.

Related