0

I am trying to transition an ImageView from an item within my RecyclerView inside a fragment to an Activity. I have declared the following in my

styles.xml

<!-- enable window content transitions -->
<item name="android:windowActivityTransitions">true</item>

<!-- specify enter and exit transitions -->
<!-- options are: explode, slide, fade -->
<item name="android:windowEnterTransition">@transition/change_image_transform</item>
<item name="android:windowExitTransition">@transition/change_image_transform</item>

<!-- specify shared element transitions -->
<item name="android:windowSharedElementEnterTransition">
  @transition/change_image_transform
</item>
<item name="android:windowSharedElementExitTransition">
  @transition/change_image_transform
</item>

Then in my

Recyclerview Adapter

I am starting the activity using

if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.Lollipop)
{ 
    ActivityOptionsCompat options = ActivityOptionsCompat.MakeSceneTransitionAnimation((Activity)Context, pec.View, "profile");
    Context.StartActivity(intent, options.ToBundle());
}

I have defined both ImageViews with the

transitionName="profile"

and also have a

transition/change_image_transform.xml

that looks like

<?xml version="1.0" encoding="utf-8" ?>
<transitionSet xmlns:android="http://schemas.android.com/apk/res/android">
  <changeImageTransform/>
</transitionSet>

There are no errors, just no transition takes place between my item in the recyclerview and the activity.

Carl
  • 841
  • 1
  • 13
  • 33

1 Answers1

1

If you using the MakeSceneTransitionAnimation you do not need to design the transition in the xml file. Just set <item name="android:windowActivityTransitions">true</item> is enough.

When you do the imageview transition you should make sure the transition name is same.

I have a demo it should be helpful for you, the view transition from MainActivity to Activity1. You can refer to the project and find the solution.

enter image description here

Mike Ma
  • 2,017
  • 1
  • 12
  • 17
  • Does the image have to be fixed on both ImageViews? I am loading the activity from a RecyclerView so each row will have a different image and I want to pass that across to the activity. – Carl Dec 21 '16 at 10:28
  • @Carl Image do not need to fixed on both imageviews. Use the `Pair` to defined the muti imageview with same transition name. You can put a id in the `intent` when the `DetialActivity` on create you can receive the id and set the different image in the`'ImageView` of `DetialActivity` – Mike Ma Dec 26 '16 at 07:48
  • Found the issue, I was using ActivityOptionsCompat, now I've changed it to ActivityOptions everything is working. Thanks for your help. – Carl Dec 29 '16 at 22:07
  • can i do this from activity to fragment? – GvSharma Oct 23 '17 at 18:46