Android shared element transition ToolBar overlap

multiple shared element transition android
custom shared element transition android
android shared element transition fragment
android shared element transition recyclerview
android shared element transition listview
android shared element transition viewpager
shared element transition android not working
android transition animation

I've implemented shared element transitions for my app, where the transition begins on an image from a Fragment (with RecyclerView) inside a ViewPager on the home screen and expands into full screen gallery view, again within a Fragment in a ViewPager. This is all working fine except that if the image is not fully visible it goes on top of the TabBar before expanding into full screen. Here's what's happening:

My enter transition looks like this:

<?xml version="1.0" encoding="utf-8"?>
<fade xmlns:android="http://schemas.android.com/apk/res/android">
    <targets>
        <target android:excludeId="@android:id/statusBarBackground"/>
        <target android:excludeId="@android:id/navigationBarBackground"/>
    </targets>
</fade>

And exit:

<?xml version="1.0" encoding="utf-8"?>
<transitionSet xmlns:android="http://schemas.android.com/apk/res/android"
android:transitionOrdering="together"
android:duration="500">
    <fade>
        <targets>
            <target android:excludeId="@android:id/statusBarBackground" />
            <target android:excludeId="@android:id/navigationBarBackground" />
        </targets>
    </fade>
</transitionSet>

And in the shared element callback of the calling activity I've got this:

View navigationBar = activity.findViewById(android.R.id.navigationBarBackground);
View statusBar = activity.findViewById(android.R.id.statusBarBackground);
if (navigationBar != null) {
    names.add(navigationBar.getTransitionName());
    sharedElements.put(navigationBar.getTransitionName(), navigationBar);
}
if (statusBar != null) {
    names.add(statusBar.getTransitionName());
    sharedElements.put(statusBar.getTransitionName(), statusBar);
}

Finally in styles.xml for the activity theme:

<item name="android:windowContentTransitions">true</item>
<item name="android:windowEnterTransition">@transition/details_window_enter_transition</item>
<item name="android:windowReturnTransition">@transition/details_window_return_transition</item>

I don't really understand how the toolbar (or actionbar) can be excluded by the transition without getting this overlap. Perhaps a way to do it would be to somehow force the image to be clipped at the top part so that it doesn't become fully visible when under the ToolBar and expands only from the visible rectangle.

I've tried adding <target android:excludeId="@id/action_bar_container"/> to the targets of the animation but the same thing happens still.

Any suggestions are welcome.

I found a similar problem in my project.Add below code in your style.

<item name="android:windowSharedElementsUseOverlay">false</item>

It works for me.

Shared Element Transitions - Fixing Flashing/Blinking, Shared Element Transitions - Part 5: Fixing Flashing/Blinking For the next few examples I've added in a Toolbar as I believe a lot of you will <fade xmlns:​android="http://schemas.android.com/apk/res/android"> <targets>  In my app m trying to implement shared element transition between listview name from one activity and Toolbar title in the next activity. The problem i am facing is that shared element is not animated as it should be instead its animated along with the entire layout enter and exit transitions.

I came up with a temporary workaround. Before the shared element transition is executed, the calling activity checks whether the target view is within the bounds of the RecyclerView. If not, the RecyclerView is smooth-scrolled to show the full view and once that is finished the transition runs. If the view is fully visible, then transitions runs normally.

// Scroll to view and run animation when scrolling completes.
recycler.smoothScrollToPosition(adapterPosition);
recycler.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {

    @Override
    public boolean onPreDraw() {
        recycler.getViewTreeObserver().removeOnPreDrawListener(this);
        // Open activity here.
        return true;
    }
});

Here's the result, not too bad until I find a better solution:

How to apply Shared Element Transitions in Android, I found a similar problem in my project.Add below code in your style. <item name​="android:windowSharedElementsUseOverlay">false</item> It  Assign a Common Transition Name. Within two fragments let's assign a common transition name to the shared elements in both layouts. Use the android:transitionName attribute and put the view inside both FirstFragment and SecondFragment: <androidx.cardview.widget.CardView > <ImageView android:id="@+id/ivProfile" android:transitionName="profile" android:scaleType="centerCrop" android:layout_width="match_parent" android:layout_height="160dp" /> </androidx.cardview.widget.CardView>.

I guess i have the proper answer for this question. This issue happening because on the second activity you do not have toolbar at all, so it can not be added to transition as shared element. So in my case i added some 'fake toolbar' to my second activity, which have 0dp height. Then you can add toolbar from first activity as a shared element, and give him change bounds animation, so toolbar will collapse at the same time as image and image will no longer be 'over' toolbar.

My 'fake toolbar' view:

    <View
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:background="@color/colorPrimary"
    android:elevation="10dp"
    android:outlineProvider="none"
    android:transitionName="toolbar_transition" />

important notes:

-view have to have non-transparent background

-i added elevation to be sure that my view i 'over' image

-elevation causes shadow, whick i did not wanted, so i set outilenProvider as none

Next all you have to do is add your toolbar to shared elements

    sharedElements.add(new Pair<>(toolbar, "toolbar_transition"));

[Motion] Can't use both Container transition and Shared element , Shared elements transitions were introduced in Android 5.0 to make view button in your Toolbar or if the user presses device's back button. A shared element transition determines how views that are present in two fragments transition between them. For example, an image that is displayed on an ImageView on both Fragment A and Fragment B transitions from A to B when B becomes visible.

Material Animations · GitHub, Here is how it looks with a shared element transition instead: on my second fragment, and android:transitionName="shared_element_container" being set to The returnTransform seems to have an overlay over the toolbar. Custom Shared Elements Transitions: In Android Lollipop (Android 5.0), the default shared elements transition is a combination of 4 transitions: Change Bounds – It captures the layout bounds of target views before and after the scene change and animates those changes during the transition.

#5.8 Android Activity Transition Overlap. Android Material Design , Android Transition Framework can be used for three main things: Animate Animate shared elements (Hero views) in transitions between activities. You can define if enter and exit transitions can overlap each other. Execute a Circular Reveal animation for the Toolbar; Execute a scale up animation on  Video 3.1illustrates how shared element transitions are used in the Google Play Music app. The transition consists of two shared elements: an ImageViewand its parent CardView. During the transition, the ImageViewseamlessly animates between the two activities while the CardViewgradually expands/contracts into place.

Shared Element Transitions In-Depth (part 3a), This post will give an in-depth analysis of shared element transitions and by the framework, we must discuss the shared element overlay. A tutorial to show how to fix the flashing/blinking when using Shared Element Transitions on Android.

Comments
  • This will reduce the alpha value of the shared element view, which makes sense but doesn't look good in my case. However, it is a valid solution so I'll mark as correct.
  • I'm going mad, I have the same issue! How did you manage to implement this scrolling?
  • @user11230 edited my answer with an example of how to scroll and wait until the scroll completes.
  • Thank you very much but it does not work. If you could please take a look I would be eternally grateful. I'm trying to fix this since may. pastebin.com/uyEpfjvM i.imgur.com/cj3kexs.mp4