Answer the question
In order to leave comments, you need to log in
Transition from Fragment with RecyclerView to DetailFragment?
Hello. I have a question about animation in android.
I'm using Transition to animate the transition from RecyclerView to Fragment with card details.
The animation is processed only when switching to the DetailFragment, and when the back button is pressed, it abruptly switches back (without animation for the selected objects).
It is necessary that the same animation would work out when moving back.
Tell me what to do?
RecViewAdapter Code
@Override
public void onBindViewHolder(final RVTwoAdapter.ViewHolder holder, final int position) {
holder.textView.setText(elements.getElements().get(position).getName());
holder.photo_detail.setTransitionName(holder.transitionNamephoto_detail + position);
holder.cardViewDetail.setTransitionName(holder.transitionNameCardViewDetail + position);
holder.photo_detail.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
DetailsFragment detailsFragment = new DetailsFragment();
Bundle bundle = new Bundle();
bundle.putString("transitionNameForDetail", holder.photo_detail.getTransitionName());
bundle.putString("transitionNameForDetailCardView", holder.cardViewDetail.getTransitionName());
detailsFragment.setArguments(bundle);
detailsFragment.setSharedElementEnterTransition(new DetailsTransition());
detailsFragment.setSharedElementReturnTransition(new DetailsTransition());
fragmentManager.beginTransaction()
.replace(R.id.container, detailsFragment)
.addToBackStack(null)
.addSharedElement(holder.photo_detail, holder.photo_detail.getTransitionName())
.addSharedElement(holder.cardViewDetail, holder.cardViewDetail.getTransitionName())
.commit();
}
});
}
public class DetailsFragment extends Fragment {
ImageView photo_detail;
CardView cardViewDetail;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
setSharedElementReturnTransition(new Fade(Fade.IN));
setExitTransition(new Fade(Fade.OUT));
View view = inflater.inflate(R.layout.fragment_deatail, container, false);
photo_detail = (ImageView) view.findViewById(R.id.photo_detail);
cardViewDetail = (CardView) view.findViewById(R.id.cardviewDetail);
photo_detail.setTransitionName(getArguments().getString("transitionNameForDetail"));
cardViewDetail.setTransitionName(getArguments().getString("transitionNameForDetailCardView"));
return view;
}
}
public class DetailsTransition extends TransitionSet {
public DetailsTransition() {
setOrdering(ORDERING_TOGETHER);
addTransition(new ChangeBounds());
addTransition(new ChangeClipBounds());
addTransition(new ChangeImageTransform());
addTransition(new ChangeTransform());
setInterpolator(new FastOutSlowInInterpolator());
}
}
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