Activity and fragmented transitions in Lollipop

I am trying to wrap around a new Activity Transition framework in Lollipop . The activity transition works pretty well, and there is basic information here , but the Fragment Transition undocumented, and I can't get it to work. I tried this use case (very common in Android):

case 1: ActA + FragA → ActB + FragB

with sharedElement being an image in FragA and FragB . I did not come up with working code, so I took a step back and tried

Case 2: ActA + FragA → ActB

from sharedElement to FragA and ActB . The animation will not work, I can only see that when I click on the image on FragA, the image disappears, and after the duration of the animation, it appears in ActB. General views outside FragA, but inside ActA (e.g. Toolbar ) are animated correctly.

In this case, sharedImage is an imageView in RecyclerView, maybe the android:transitionName="shared_icon" xml tag android:transitionName="shared_icon" in the xml elements layout doesn't work?

This is my topic:

  <!-- 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> 
+8
android android-5.0-lollipop android-fragments shared-element-transition activity-transition
source share
1 answer

Fragment transitions are designed to work between fragments in the same Activity. If you have two different actions, regardless of whether they have fragments or not, you use Activity Transitions. Feel free to ignore all fragment transition properties.

In your case 2, you should not have a problem with the transition, if it is configured correctly. I assume that your application theme is not derived from android: Theme.Material, so you need one more property:

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

windowContentTransitions allows you to use the TransitionManager to seamlessly animate between your window's setContentView.

When you have a snippet in your running activity, such as case 1, you might need to do as @AlexLockwood suggested: postponeEnterTransition. However, you can also use:

 getFragmentManager().executePendingTransactions(); 

inside your onCreate () to make the fragment load immediately so that the Transition Activity sees all the views in your layout.

+6
source share

All Articles