ralphilius
7/8/2015 - 4:06 PM

ImageView Transitions

ImageView Transitions

<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>
<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());
            }
        });