I'm trying to wrap my head around the new Activity
Transition
framework in Lollipop
.
The Activity Transition works pretty straighforward and there are some basic info here, but the Fragment
Transition
is undocumented and I can't get it to work.
I've tried this use case (very common in Android):
case 1: ActA+FragA -> ActB+FragB
with the sharedElement being an image in FragA
and FragB
. I didn't come up with working code, so I went a step back and tried
case 2: ActA+FragA -> ActB
with a sharedElement on FragA
and ActB
. The animation won't work, I can only see that when I click the image on FragA, the image disappear and after the animation's duration it pops up in ActB. Shared views outside FragA but inside ActA (the Toolbar
for example) animate correctly.
In this case the sharedImage is an imageView in a RecyclerView, could it be that the xml tag android:transitionName="shared_icon"
in the item's layout xml doesn't work?
This is my Theme:
<!-- Window Transactions -->
<item name="android:windowContentTransitions">true</item>
<item name="android:windowAllowEnterTransitionOverlap">true</item>
<item name="android:windowAllowReturnTransitionOverlap">true</item>
<item name="android:fragmentAllowEnterTransitionOverlap">@bool/true_bool</item>
<item name="android:fragmentAllowReturnTransitionOverlap">@bool/true_bool</item>
<item name="android:windowEnterTransition">@transition/window_transition.xml</item>
<item name="android:windowExitTransition">@transition/window_transition.xml</item>
<item name="android:fragmentEnterTransition">@transition/window_transition.xml</item>
<item name="android:fragmentReturnTransition">@transition/window_transition.xml</item>
<item name="android:fragmentReenterTransition">@transition/window_transition.xml</item>
<!-- Shared Element Transactions -->
<item name="android:windowSharedElementEnterTransition">@transition/shared_elements_transform.xml</item>
<item name="android:windowSharedElementExitTransition">@transition/shared_elements_transform.xml</item>
<item name="android:fragmentSharedElementEnterTransition">@transition/shared_elements_transform.xml</item>
<item name="android:fragmentSharedElementReturnTransition">@transition/shared_elements_transform.xml</item>
window_transition.xml:
<?xml version="1.0" encoding="utf-8"?>
<transitionSet xmlns:android="http://schemas.android.com/apk/res/android"
android:ordering="together"
android:duration="@integer/act_transition_duration">
<changeBounds />
<changeTransform />
<changeClipBounds />
<changeImageTransform />
</transitionSet>
shared_element_transition.xml:
<?xml version="1.0" encoding="utf-8"?>
<transitionSet xmlns:android="http://schemas.android.com/apk/res/android"
android:ordering="together"
android:duration="@integer/act_transition_duration">
<changeImageTransform />
<changeBounds />
</transitionSet>