0

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

  1. Shared element transition in RecyclerView
  2. How to animate RecyclerView items when they appear

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.

  • 1
    This may not possible. As we commonly specify where to put shared element transition effect. And in recycler view there are dynamic views. –  Jul 01 '21 at 14:57

0 Answers0