I'm having an issue with swiping a recyclerview item. I've found the answers to most of what I'm trying to do and the methods do the job. The objective was to swipe a view in one direction to expose a button for one option or expose a button for another option when swiped the opposite direction. I've included a screen shot to show the result. I was able to limit how far you can swipe by manipulating the dX before passing it to the super in the onChildDraw based on the size of the buttons I'm painting. This works beautifully while you're dragging but when you lift your finger the animation returning the view to that point follows. This makes the view animate from where you dragged to where it stops where your button ends. It looks odd and not sure what to override to cancel this behavior when the button has been fully exposed. Here's the code in my SwipeController if it would help. I use the newDX to limit how far the drag is "considered"
The view does actually return to the point shown in the image below and I am able to use it and click the button. Just looks funny doing what it's doing.
The view does actually return to the point shown in the image below and I am able to use it and click the button. Just looks funny doing what it's doing.
Java:
@Override
public void onChildDraw(@NonNull Canvas c, @NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) {
if (actionState == ACTION_STATE_SWIPE) {
if (buttonShowedState != ButtonsState.GONE) {
if (buttonShowedState == ButtonsState.LEFT_VISIBLE) {
dX = Math.max(dX, buttonWidth);
}
if (buttonShowedState == ButtonsState.RIGHT_VISIBLE) {
dX = Math.min(dX, -buttonWidth);
}
super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
} else {
setTouchListener(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
}
}
if (buttonShowedState == ButtonsState.GONE) {
float newDx = dX;
if (newDx < 0) {
if (newDx <= -buttonWidth) {
newDx = -buttonWidth;
}
} else {
if (newDx >= buttonWidth) {
newDx = buttonWidth;
}
}
super.onChildDraw(c, recyclerView, viewHolder, newDx, dY, actionState, isCurrentlyActive);
}
currentItemViewHolder = viewHolder }
Last edited: