вместо того, чтобы делать это, вы можете использовать пары.
holder.itemView.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(mContext /*your context from main activity*/, Destination.class);
Pair[] pairs = new Pair[3]; /* careful about the number and how many element you want to animate*/
pairs[0]= new Pair<View, String>(holder.X /*item to animate to next activity*/, "transitionX" /* name of transition animation that you have to set on your xml file of the item*/);
pairs[1]= new Pair<View, String>(holder.Y, "transitionY");
pairs[2]= new Pair<View, String>(holder.Z, "transitionZ");
ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation((Activity) mContext, pairs);
// start the activity
mContext.startActivity(intent, options.toBundle());
}
});
class CourseViewHolder extends RecyclerView.ViewHolder {
TextView X;
ImageView Y;
LinearLayout Z; /* you can animate layout as well*/
private CourseViewHolder(View itemView) {
super(itemView);
X= itemView.findViewById(R.id.x);
Y=itemView.findViewById(R.id.y);
Z=itemView.findViewById(R.id.z);
}
}
itemView.xml file
<TextView
android:id="@+id/x"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:transitionName="transitionX"/>
<ImageView
android:id="@+id/x"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:transitionName="transitionY"/>
<LinearLayout <!-- you can animate Layout to another object -->
android:id="@+id/Z"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:transitionName="transitionZ">
----------------------
--------------------
</LinearLayout>
файл destinationclass.xml
<TextView
android:id="@+id/x_will_transit_to"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:transitionName="transitionX"/> <!-- The name of transition must be the same as java file and both of the element from xml file -->
<!-- You can also animate one type of View to another when transition take place -->
<Button
android:id="@+id/y_will_transit_to"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:transitionName="transitionY"/>
<ImageView
android:id="@+id/z__will_transit_to"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:transitionName="transitionZ"/>
не имеет значения, переходите ли вы от повторного просмотра к фрагменту или что-то еще ... вам просто нужно установить анимацию внутри действия или где происходит onClick. дайте переходу одно и то же имя в макете обоих файлов, среди которых будет происходить переход. и, наконец, в случае, если вы проверяете в своем эмуляторе или мобильном устройстве, которое вы тестируете, приложение должно иметь весь масштаб анимации как минимум 1x (в варианте разработчика). Надеюсь, это поможет, даже если это не тот ответ, который вы ищете.