0

I have been following these guides [1, 2] to understand more about activity and fragment transitions and animations in Android.

My scenario seems to be different to all three examples given, in that I have an <ImageView> within a fragment of my HomePageActivity and OnClick of that ImageView within my HomePageFragment it loads up DetailActivity and the DetailFragment loads an <ImageView> at the top.

How can I provide a smooth transition animation of the first <ImageView> into the second?

I am using Xamarin for .NET, but I can follow Java logic if provided.

HomePageFragment.cs (I was trying a few different things)

var intent = new Intent(this.Activity, typeof(DetailActivity));
intent.PutExtra("page", JsonConvert.SerializeObject(page));
// .. test
SharedElementReturnTransition = TransitionInflater.From(this.Activity).InflateTransition(Resource.Transition.change_image_trans);
ExitTransition = TransitionInflater.From(this.Activity).InflateTransition(Resource.Transition.fade_trans);
// .. end test
//var options = ActivityOptionsCompat.MakeSceneTransitionAnimation(this.Activity, p1);
this.Activity.StartActivity(intent/*, options.ToBundle()*/);

DetailActivity.cs

var frag = new PageDetailFragment();
if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
{
    frag.SharedElementEnterTransition = TransitionInflater.From(this).InflateTransition(Resource.Transition.change_image_trans);
    frag.EnterTransition = TransitionInflater.From(this).InflateTransition(Resource.Transition.fade_trans);
}

frag.Arguments = Intent.Extras; // pass arguments across
SupportFragmentManager.BeginTransaction()
    .Replace(Resource.Id.content_frame, frag)
    .Commit();

excerpt home_tile_item.axml (repeated via RecyclerView)

<ImageView
        android:id="@+id/imageTile"
        android:transitionName="topImageTransition"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:adjustViewBounds="true"
        android:scaleType="fitCenter" />

excerpt page_detail_fragment.axml

<ImageView
            android:id="@+id/top_image"
            android:transitionName="topImageTransition"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:maxHeight="400dp"
            android:adjustViewBounds="true"
            android:scaleType="fitCenter" />

Also top_image's background is provided by Universal Image Loader, and in some cases may not load the same URL sent to imageTile. Additionally, is this ok?

GONeale
  • 26,302
  • 21
  • 106
  • 149

0 Answers0