Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shared element transition in RecyclerView

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());
            }
        }
}
like image 574
RandomyzeEverything Avatar asked Dec 06 '16 08:12

RandomyzeEverything


People also ask

What is shared Element transition?

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.

What is shared elements in react native?

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.


1 Answers

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>
like image 174
Manthan Patel Avatar answered Oct 21 '22 19:10

Manthan Patel