Home » Android » android – Shared element transition leaves a strange white background between first activity and second transparent activity

android – Shared element transition leaves a strange white background between first activity and second transparent activity

Posted by: admin May 14, 2020 Leave a comment

Questions:

Recently I faced up with a weird problem.
I have two activities. The first one contains a grid with a thumbnails. A kind of a gallery. And the second one contains a view pager with fragments and behaves like an image viewer where you can slide between images.
I use a shared element transition to start the second activity. Just like Google Photo app. On the second activity I can swipe to top or bottom to dismiss the activity with a fade away transition of the background. I made my second activity fully transparent:

<item name="android:windowBackground">@color/palette_transparent</item>
<item name="android:colorBackgroundCacheHint">@null</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowAnimationStyle">@android:style/Animation</item>

But the problem is when I swipe an image to top/bottom and the second activity’s background fades I can see a white background but not the first activity. If I start the second activity without shared element transition everything is fine.

I made a research and found out that this white layer probably overlays the first activity. It is not a part of the second activity as I can see in Stetho view hierarchy.

Probably my explanation is not very good neither my English language so here a couple of videos too clarify my problem.

Video Without transition and Video With transition

How to&Answers:

This should help:

<item name="android:windowEnterTransition">@android:transition/no_transition</item>
<item name="android:windowExitTransition">@android:transition/no_transition</item>