Skip to content

Instantly share code, notes, and snippets.

@KarthikKumarBA
Created November 24, 2016 10:26
Show Gist options
  • Save KarthikKumarBA/f03277808b25c1d66d8733193f28a9ee to your computer and use it in GitHub Desktop.
Save KarthikKumarBA/f03277808b25c1d66d8733193f28a9ee to your computer and use it in GitHub Desktop.
Activity Shared Element Transition
ImageView imageView = (ImageView) findViewById(R.id.image_star);
TextView textViewName = (TextView) findViewById(R.id.text_view_name);
Pair[] pairs = new Pair[2];
pairs[0] = new Pair<View, String>(imageView, "transition_star");
pairs[1] = new Pair<View, String>(textViewName, "transition_name");
ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(this, pairs);
Intent i = new Intent(this, TransitionActivity.class);
i.putExtra("KEY_TYPE", "SharedTransition");
startActivity(i, options.toBundle());
<!--Add transitionName attribute to the views to which you want to apply shared transition
animation-->
<ImageView
android:id="@+id/image_star"
android:transitionName="transition_star"
android:src="@android:drawable/btn_star"
android:layout_gravity="center"
android:layout_width="150dp"
android:layout_height="150dp"/>
<TextView
android:id="@+id/text_view_name"
android:transitionName="transition_name"
android:layout_marginTop="20dp"
android:textStyle="bold"
android:layout_gravity="center"
android:text="Transition Name"
android:textSize="30sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment