Skip to content

Instantly share code, notes, and snippets.

@ralphilius
Created July 8, 2015 16:06
Show Gist options
  • Save ralphilius/fde5b8f9e25a7a85855f to your computer and use it in GitHub Desktop.
Save ralphilius/fde5b8f9e25a7a85855f to your computer and use it in GitHub Desktop.
ImageView Transitions
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/cardImage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="centerCrop"
android:transitionName="cardImage"
android:src="@drawable/smiley"/>
</RelativeLayout>
View cardImage = (ImageView) findViewById(R.id.cardImage);
cardImage.setTransitionName("cardImage");
ImageView cardImage = (ImageView) findViewById(R.id.cardImage);
cardImage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//This is where the magic happens. makeSceneTransitionAnimation takes a context, view, a name for the target view.
ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(MaterialActivity.this, cardImage, "cardImage");
Intent intent = new Intent(OriginalActivity.this, DetailActivity.class);
startActivity(intent, options.toBundle());
}
});
<resources>
<style name="AppTheme" parent="android:Theme.Material.Light">
<!-- enable window content transitions -->
<item name="android:windowContentTransitions">true</item>
<!-- enable overlapping of exiting and entering activities-->
<item name="android:windowAllowEnterTransitionOverlap">true</item>
<item name="android:windowAllowReturnTransitionOverlap">true</item>
</style>
</resources>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment