Skip to content

Instantly share code, notes, and snippets.

@fnk0
Last active March 8, 2016 17:52
Show Gist options
  • Select an option

  • Save fnk0/19e4eb0a8c0211455f62 to your computer and use it in GitHub Desktop.

Select an option

Save fnk0/19e4eb0a8c0211455f62 to your computer and use it in GitHub Desktop.
ActivityTransition
<!--
Define the transitionName in both ImageViews in the source XML and the Destination XML
It is very important for then to match
-->
<android.support.v7.widget.AppCompatImageView
android:id="@+id/myImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
app:layout_collapseMode="parallax"
android:transitionName="transitionImage"
/>
String pictureUrl = extras.getString(Const.EXTRA_IMAGE);
// We still need to Load the image
loadImage(pictureUrl);
Intent intent = new Intent(getActivity(), DestinationActivity.class);
// We want the URL as soon as the other Activity starts to load the image faster
intent.putExtra(Const.EXTRA_IMAGE, pictureURL);
// Check if is Lollipop first
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
// transitionImageView is the ImageView that will be transitioned
ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(getActivity(), transitionImageView, "transitionImage");
startActivity(intent, options.toBundle());
} else {
startActivity(intent);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment