I have a recyclerview which shows images. When I click it opens new Activity which shows the same image in fullscreen. I want to setup the Shared Element Transition effect between recyclerView Items and new Activity. I can't figure out how to do this.
I went through this links
But, I couldn't find appropriate answer for my situation. I am Using callback of onImageClickListner in my Fragment. Adapter
public PhotosAdapter(Context context, ArrayList<ImageModel> arrayList, Activity activity, OnImageClickListner listner) {
this.context = context;
this.arrayList = arrayList;
this.activity = activity;
this.listner = listner;
}
@NonNull
@Override
public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.single_view, parent, false);
return new MyViewHolder(view,listner);
}
@Override
public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
GlideApp.with(context)
.load(arrayList.get(position).getUri())
.diskCacheStrategy(DiskCacheStrategy.RESOURCE)
.into(holder.img);
Log.d("FetchImages(): "," Glide Called");
}
@Override
public int getItemCount() {
return arrayList.size();
}
public static class MyViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
ImageView img;
OnImageClickListner listner;
public MyViewHolder(@NonNull View itemView, OnImageClickListner listner) {
super(itemView);
this.listner = listner;
itemView.setOnClickListener(this);
img = itemView.findViewById(R.id.imgShare);
}
@Override
public void onClick(View v) {
listner.onclick(getAdapterPosition());
}
}
public interface OnImageClickListner{
void onclick(int position);
}
in Fragment
@Override
public void onclick(int position) {
Intent intent = new Intent(getActivity(), FullPhoto.class);
intent.putExtra("uri",arrayList.get(position).getUri().toString());
startActivity(intent);
}
This is opeining the new Activity but, without any animations. so, I want to put shared element transition between recyclerview item and new activity. So, when user clicks on image it will animate and then new activity will be opened.