1

I would like to know how the MaterialContainerTransform can be implemented from a FAB to a fragment. I have followed the tutorial provided by Google but without success.

I want to achieve this:

enter image description here

An animation that does exactly that (An animation that starts in the FAB and ends in the other fragment) between two fragments using Navigation.

What I have tried so far ...

Fragment A:

fabCreateTrip.setTransitionName("sharedElementTrip");
FragmentNavigator.Extras.Builder extras = new FragmentNavigator.Extras.Builder();
extras.addSharedElement(fabCreateTrip, fabCreateTrip.getTransitionName());

Navigation.findNavController(view).navigate(R.id.navigation_createTrip, null, null, extras.build());

Fragment B:

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        setSharedElementEnterTransition(new MaterialContainerTransform());
  }
}

XML Fragment B, root of the fragment:

<androidx.coordinatorlayout.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/containerMakeTrip"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:transitionName="sharedElementTrip"
    android:orientation="vertical">

This is the error it gives me:

E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.everything.onTrans, PID: 19621
java.lang.IllegalArgumentException: Invalid Transition types
at androidx.fragment.app.FragmentTransition.chooseImpl(FragmentTransition.java:521)
at androidx.fragment.app.FragmentTransition.configureTransitionsReordered(FragmentTransition.java:240)
at androidx.fragment.app.FragmentTransition.startTransitions(FragmentTransition.java:152)
at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:2005)
at 
androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1953)
at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:1849)
at androidx.fragment.app.FragmentManager$4.run(FragmentManager.java:413)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:237)
at android.app.ActivityThread.main(ActivityThread.java:7811)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1076)

Google Tutorial: material-container-transform

Alex Rivas
  • 161
  • 2
  • 9
  • Usually this error happens if you are mixing transitions from androidx and the platform. Are you importing classes from `import com.google.android.material.transition` and `com.google.android.material.transition.platform`? Check also the `Hold` class. – Gabriele Mariotti Jun 07 '20 at 22:35

0 Answers0