4

I'm working on making beautiful transitions on my app. I succeed in sharing 1 element but failed when I shared multiple elements. The following code only animates one element of the 3 shared. I don't know why. It seems that this happens because of the last view listed in the layout xml file.

Here is what I did :
In my theme :

<item name="android:windowContentTransitions">true</item>
<item name="android:windowAllowEnterTransitionOverlap">true</item>
<item name="android:windowAllowReturnTransitionOverlap">true</item>

In Activity OnCreate :

getWindow().setSharedElementExitTransition(TransitionInflater.from(this).inflateTransition(R.transition.change_image_transform));

In Activity Clic listener:

ImageView header = (ImageView) findViewById(R.id.iv_header);
ImageView tv_menu_home = (ImageView) findViewById(R.id.tv_menu_home);
ImageView tv_menu_prefs = (ImageView) findViewById(R.id.tv_menu_prefs);

ActivityOptions optionsCompat = ActivityOptions.makeSceneTransitionAnimation(MainActivity.this
                        ,Pair.create((View)tv_menu_prefs,tv_menu_prefs.getTransitionName())
                        ,Pair.create((View)tv_menu_home,tv_menu_home.getTransitionName())
                        ,Pair.create((View)header,header.getTransitionName())
                );

In change_image_transform.xml:

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

In both layout xml

...
<ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/tv_menu_home"
        android:src="@drawable/bouton_home"
        android:contentDescription="@string/hint_accueil_desc"
        android:transitionName="MyTransitionHome"
        />
...
<ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/tv_menu_prefs"
        android:src="@drawable/bouton_pref"
        android:contentDescription="@string/hint_preferences_desc"
        android:transitionName="MyTransitionPrefs"
        />
...
<ImageView
    android:id="@+id/iv_header"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/fakeHeader"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="20dp"
    android:src="@drawable/header"
    android:transitionName="MyTransition" />
Lyubomyr Shaydariv
  • 20,327
  • 12
  • 64
  • 105
castrogne
  • 521
  • 1
  • 4
  • 17

0 Answers0