Lollipop multiple Shared view transition
I am working on creating beautiful transitions in my application. I was able to split one item but failed when I split multiple items. The following code only animates one element out of 3 common ones. I do not know why. It looks like this is due to the last view specified in the layout XML file.
Here's 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 the OnCreate action:
getWindow().setSharedElementExitTransition(TransitionInflater.from(this).inflateTransition(R.transition.change_image_transform));
In action 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 the change_image_transform.xml file:
<?xml version="1.0" encoding="utf-8"?>
<transitionSet xmlns:android="http://schemas.android.com/apk/res/android">
<changeImageTransform />
</transitionSet>
In both layouts 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" />
+3
source to share
No one has answered this question yet
Check out similar questions:
fourteen