We are implementing ItemTouchHelper in a RecyclerView, we are making a Override of onChildDraw when we swipe to the left in the RV, the problem is, if I have a RecyclerView with X size, and I try to dismiss the 2, 3, 4 or 5 elements, the only one that show the text is the first element in the List, but, if is an image it work pretty well
@Override
public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) {
if (viewHolder.getAdapterPosition() == -1)
return;
View itemView = viewHolder.itemView;
Paint paint = new Paint();
paint.setColor(Color.WHITE);
paint.setTextSize(40);
paint.setTextAlign(Paint.Align.CENTER);
String inbox = itemView.getContext().getResources().getString(R.string.sendinbox);
c.drawText(inbox, itemView.getRight() - 200, itemView.getHeight()/2, paint);
super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
}
It's probably too late but I'll answer anyways. Your problem was when drawing Text on Canvas, you have to set X and Y position, and as the canvas is the same for all the items, you were constantly setting the same text at the same Y position. The solution was to add itemView.getTop() to your Text's Y position:
c.drawText(inbox, itemView.getRight() - 200, itemView.getTop() + itemView.getHeight() / 2, paint);
Sorry my english
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With