0

I have a horizontal recyclerview which implements ItemTouchHelper callback for dragging and reordering cells. When a cell is being moved i want to shrink all of the cells widths so they all appear on screen. In onItemSelected() i can successfully change the size of the cell currently being moved, and revert back in onItemClear.

However, i want to resize all cells and not just the current cell. What is the best approach for this?

I tried creating a function in my adapter class and calling it to resize via notifyDataSetChanged() however it was removing the current cell being moved.

Is there a way to do this as part of my ItemTouchHelperCallback - creating a similar function as onItemSelected but updating all other cells?

nt95
  • 455
  • 1
  • 6
  • 21

1 Answers1

0

I am not sure if I completely understand what you are trying to do, but I think this might help:


        int childs = recyclerView.getChildCount();
        for (int i = 0; i < childs; i++) {
            View child = recyclerView.getChildAt(i);
            if (child != null) {
                RecyclerView.ViewHolder vholder = recyclerView.getChildViewHolder(child);
                if (vholder != null) {
                    ViewHolder holder = (ViewHolder) vholder;
                    if (holder.view != null) {
                        LayoutParams params = (LayoutParams)holder.view.getLayoutParams();
                        params.width = <new_width>;
                        params.height = <new_height>;
                        holder.view.setLayoutParams(params);
                    }
                }
            }
        }

Happy coding !!

  • This is the code that will resize the childViews correctly, however my issue is when to call this. ItemTouchHelper only monitors the specific item that is being moved. This is a good article on it https://medium.com/@ipaulpro/drag-and-swipe-with-recyclerview-b9456d2b1aaf i essentially want to call the code that you've written but in the ItemTouchHelper. – nt95 May 15 '19 at 15:02