Answer the question
In order to leave comments, you need to log in
How to correctly arrange Shared element transition from RecyclerView to RecyclerView?
Hello, I'm trying to make a Shared element transition from a RecyclerView (located in a fragment) to a RecyclerView (located on an activity).
The animation turned out only when you exit (that is, when you press the back button), and when you enter, it just flickers and the activity appears.
What I've done?
In two adapters I made the TransitionName assignment.
I also added the following code to the receiving activity:
getWindow().setSharedElementEnterTransition(TransitionInflater.from(this).inflateTransition(R.transition.shared_element_transation));
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
holder.myTextView.setText(mData.get(position).getText());
holder.imageview.setImageResource(mData.get(position).getImageid());
holder.imageview.setTransitionName("imagelogo"+ position);
}
public void onClick(View v) {
//
int pos = vHolder.getAdapterPosition();
//
Intent intent = new Intent(mContext,prophets.class);
Pair<View, String> pair1 = Pair.create((View) vHolder.imageview, vHolder.imageview.getTransitionName());
ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation((Activity) mContext,pair1);
intent.putExtra("name",0);
mContext.startActivity(intent, options.toBundle());
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<android.support.v7.widget.CardView
android:id="@+id/card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/imageid"
android:paddingLeft="1dp"
android:paddingRight="1dp"
android:layout_width="48dp"
android:layout_height="48dp"
android:src="@drawable/nuh"
android:transitionName="imagelogo"
app:civ_border_width="2dp"
app:civ_border_color="#000000"/>
<TextView
android:layout_toRightOf="@+id/imageid"
android:layout_margin="5dp"
android:id="@+id/Name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
/>
</RelativeLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
@Override
public void onBindViewHolder(final RecyclerView.ViewHolder holder, int position) {
((List3ViewHolder) holder).text.setText(((Send3) dataSet.get(position)).getText());
((List3ViewHolder) holder).imageid.setImageResource(((Send3) dataSet.get(position)).getImageid());
((List3ViewHolder) holder).imageid.setTransitionName("imagelogo" + position);
}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000">
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/imageid"
android:paddingLeft="1dp"
android:paddingRight="1dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@drawable/ic_menu_gallery"
android:transitionName="imagelogo"
app:civ_border_width="2dp"
app:civ_border_color="#FFFFFF"/>
<TextView
android:layout_marginLeft="3dp"
android:layout_marginTop="50dp"
android:layout_alignParentBottom="true"
android:layout_marginBottom="10dp"
android:id="@+id/text"
android:textColor="#fff"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:textSize="35sp"
/>
</RelativeLayout>
<b>Activity</b>
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
postponeEnterTransition();
////////////////////////////////
/
/
/
/
/
getWindow().setSharedElementEnterTransition(TransitionInflater.from(this).inflateTransition(R.transition.shared_element_transation));
/////////////////////////////
/
/
/
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question