I have: A RecyclerView where I can swipe cards to the right.
I want: Add a border to the selected card while the user is holding down her finger to swipe. However, as soon as the user lets go of their finger and aborts the swipe, I want the border to go away.
I've managed so far: I managed to implement an onItemTouchHelper that allows me to change the design during touch. It changes the color around the card to Blue during swipe. But the border just stays even when swipe is aborted.
Issue I have: The border does not go away when the user let's go of the card (aborts swipe)
Here's my code:
@Override
public void onChildDraw(@NotNull Canvas c, @NotNull RecyclerView recyclerView, @NotNull RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) {
super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
View itemView = viewHolder.itemView;
itemView.setRotation(
swipeLayoutManager.getAngle() * (dX / recyclerView.getMeasuredWidth()));
itemView.setBackgroundColor(Color.BLUE);
}
NOTE 1: The itemView.setBackgroundColor does create a Blue border around the card. But it doesn't go away when the user aborts the swipe and the card falls back into place.
NOTE 2: The itemView.setRotation method I implemented here works only applies the change in angle during the swipe but returns the angle to normal as soon as the swipe is aborted. I fail to implement the same thing with the border. When I try, it applies a color only during the swipe but the colors change all the time creating some crazy blinking effect.