Why Transition.captureStartValues and Transition.captureEndValues have the same View with same attributes?
Asked Answered
L

2

9

I have a custom Transition used in shared elements between my two Activities.

My transition doesn't work because the TransitionValues parameters has the same View with same attributes in both methods, captureStartValues and captureEndValues. So, my transition doesn't have what to do once the start and end values are the same.

Why is this happens?

Lesh answered 28/4, 2016 at 12:34 Comment(4)
Activity transitions don't actually transfer the View from one activity to the other. Instead, it transfers the location, size, and elevation, and relays out the shared element View at that location. If you need to transfer something else, that is up to you to do.Breather
But when I'm building a custom Transition used in shared elements, I need to capture those different values from start and end scene. How could I get those values if the View and attributes are the same?Aircondition
eg. I want to animate the scrollX property of my hero View. In my ActivityA's layout, my hero View has scrollX = 10. In my ActivityB's layout it has scrollX = 50. I can't animate that transition from ActivityA to ActivityB because captureStartValues and captureEndValues are always called with a View with scrollX = 50.Aircondition
Did you ever find a solution to this problem?Precautious
D
1

In my case i wanted to transition between two element's background drawable. After a lot of digging i ended getting to the realization that the view delivered to the onCaptureStartValues method is not the actual view from the first activity but rather a representation of it created in the second activity from a parcel passed down by the transition framework.

This is counter intuitive but eventually lead me to the following article which have an informative example on how to accomplish what you're after.

https://medium.com/@belokon.roman/custom-transitions-in-android-f8949870bd63

In general you use SharedElementCallback to inject custom properties into your transition object. I really hope this kind of behavior will change in the future as it feels hack-ish.

Disulfide answered 31/7, 2018 at 10:15 Comment(0)
B
0

You must set a SharedElementCallback using setEnterSharedElementCallback and override the onSharedElementStart and onSharedElementEnd and set the scroll at both the start and end. When it reverses, the end is called before the start to invert the transition.

Breather answered 30/4, 2016 at 0:34 Comment(1)
I set those scroll values at my layout xml in my Activities. I just want to read those values to make my animators in my custom Transition.Aircondition

© 2022 - 2024 — McMap. All rights reserved.