I am trying to use shared element transition on RecyclerView but it doesn't seem to work.
This is a part of my adapter in which I use makeSceneTransitionAnimation()
:
public void onBindViewHolder(final BookViewHolder holder, final int position) {
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(context, DetailsActivity.class);
ActivityOptionsCompat optionsCompat = ActivityOptionsCompat.makeSceneTransitionAnimation((Activity)context , holder.smallThumbnail, "thumbnailTransition");
context.startActivity(intent, optionsCompat.toBundle());
}
}
}
Shared Element Transition is one of the most seen animations in Android apps. This type of animation is used when we have to open an item from a ListView or RecyclerView. Shared Element Transition in Android determines how shared element views are animated from activity to activity or fragment to fragment.
react-native-shared-element provides a set of building blocks to help you build shared element transitions — animations where you transition an element in one scene smoothly into another.
In your Adapter
holder.smallThumbnail.setTransitionName("thumbnailTransition");
Pair<View, String> pair1 = Pair.create((View) holder.smallThumbnail, holder.smallThumbnail.getTransitionName());
ActivityOptionsCompat optionsCompat = ActivityOptionsCompat.makeSceneTransitionAnimation((Activity) mContext, pair1, pair2);
mContext.startActivity(intent, optionsCompat.toBundle());
In Your Detail Activity
getWindow().setSharedElementEnterTransition(TransitionInflater.from(this).inflateTransition(R.transition.shared_element_transation));
mainImage.setTransitionName("thumbnailTransition");
Here this mainimage is imageview where you want to transform your previous activity thumbnail
shared_element_transation create one xml in res>transition
<?xml version="1.0" encoding="utf-8"?>
<transitionSet xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="500">
<changeBounds />
<fade />
</transitionSet>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With