Activity and Fragment Transitions in Lollipop
S

1

8

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>
Saury answered 19/11, 2014 at 16:12 Comment(6)
I assume you have tried the advice suggested in this post (since you apparently commented on it)? plus.sandbox.google.com/u/1/+AlexLockwood/posts/FJsp1N9XNLSSymphonia
Also, if you are animating an image view... are you by any chance animating a low-resolution thumbnail in the first activity to a higher resolution image in the second activity?Symphonia
The image comes from a drawable (an app icon returned by context.getPackageManager().getApplicationIcon(packageName) to be precise). The post suggests a solution for a destination fragment (that would be case 1, which I don't know how to do at all), while in case 2 I have a source fragment that points to a destination activity. Is the postponeEnterTransition() necessary even with a simple Activity? Do I need to postpone to after I get the drawable (the imageView has a fixed width/height)?Saury
I can't say whether or not it is necessary without looking at your Activity code... but postponing the transition is the first thing I would attempt in order to fix the bug. If the transition starts too early (i.e. before your fragment transactions have been committed and laid-out, or before the high-resolution image view has been loaded, etc.) then it is certainly possible that the transition will simply fail to perform an animation (since the transition will not have successfully captured the start values it needs). See also this post: https://mcmap.net/q/1222406/-weird-issue-when-transitioning-imageview-in-android-5-0/844882Symphonia
androiddesignpatterns.com/2014/12/…Irrefrangible
No one has a working solution for CASE 1 of the question?Aborn
O
6

Fragment Transitions are meant to work between Fragments in the same Activity. If you have any two different Activities, whether they have fragments or not, you are using Activity Transitions. Feel free to ignore all the Fragment Transition properties.

In your case 2, you should have no problems with your transitions if it is set up properly. I'm guessing that your application theme does not derive from android:Theme.Material, so you need one more property:

<item name="android:windowActivityTransitions">true</item>

windowContentTransitions allows you to use a TransitionManager to smoothly animate between setContentView of your window.

When you have a fragment in your launched Activity, like case 1, you may need to do as @AlexLockwood suggested: postponeEnterTransition. However, you should also be able to use:

getFragmentManager().executePendingTransactions();

inside your onCreate() to force the fragment to load right away so that the Activity Transition will see all the views in your layout.

Obtect answered 20/11, 2014 at 0:24 Comment(1)
on using getFragmentManager().executePendingTransactions(); content of my Act->fragB is shown as blank.Gisarme

© 2022 - 2024 — McMap. All rights reserved.