1

I have two fragments being replaced in the container. My problem is with elevation shadows during the custom animation that I use for the transaction. I set the duration to two seconds to see it properly and it seems only shadows from ambient light are visible during the transaction, and key light shadows show up only after animation ends (see https://material.io/design/environment/light-shadows.html#light). Does anyone know how to deal with this?

Here's some source code and video

CardView layout

<androidx.cardview.widget.CardView
    android:id="@+id/card"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="@dimen/margin_8dp"        
    app:cardElevation="@dimen/elevation_4dp"
    app:cardCornerRadius="@dimen/corner_16dp">

Transaction code

supportFragmentManager
    .beginTransaction()
    .setCustomAnimations(
        R.anim.fade_in,
        R.anim.fade_out,
        R.anim.fade_in,
        R.anim.fade_out
    ).replace(R.id.fragment_container, questionsFragment, "questions")
    .commit()

Animation xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="2000">

    <alpha
        android:fromAlpha="0"
        android:toAlpha="1"
        android:interpolator="@android:anim/accelerate_decelerate_interpolator"/>
</set>

And this is a sample video of the issue https://www.youtube.com/watch?v=dUe1GT4dAFQ

Thanks in Advance.

Sam Joshua
  • 310
  • 6
  • 17
TheJudge
  • 576
  • 1
  • 9
  • 30
  • If you are using `FrameLayout` as container, try changing it to `FragmentContainerView`. – Rinat Diushenov May 28 '21 at 11:22
  • I was using LinearLayout for whatever reason, changed it to FragmentContainerView but the issue remains – TheJudge May 28 '21 at 11:37
  • Could be a problem with `CardView`. Can you once try enabling the `app:cardUseCompatPadding="true"`. Although I don't feel this might be it, but no harm trying. – che10 Jun 01 '21 at 12:29
  • Can you try the default anim `android.R.anim.fade_in` & `android.R.anim.fade_out` they use different interpolator – Zain Jun 02 '21 at 00:05
  • https://stackoverflow.com/a/42377786/12971639 – sandeep dhami Jun 02 '21 at 09:27
  • thanks all for recommendations, tried all of them - nothing helped – TheJudge Jun 02 '21 at 10:56
  • @sandeepdhami hi, I'm not sure what exactly from that question should be a solution. I'm quite sure that the CardView container should be able to deal with this on it's own without being wrapped in FrameLayout. And putting it in FrameLayout would probably produce few other issues. But thanks for trying to help me, I would really like to get to the bottom of this. – TheJudge Jun 02 '21 at 10:59
  • Did you try to set `supportFragmentManager.setReorderingAllowed(true)` ? – Metwalli Jun 03 '21 at 08:48
  • didn't help :/ at this point I'm considering ditching fragment transaction and using ViewPager – TheJudge Jun 03 '21 at 10:42

1 Answers1

0

Try reducing the animation duration from 2 seconds to 500ms or 1000ms.

Zain
  • 1
  • 5
  • Hi, duration of animation I'm actually using in app is 300ms, I set those two seconds there only to see the bug clearly as said in question. The problem is there of course no matter what the duration of animation is. – TheJudge Jun 04 '21 at 06:32