• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps RecyclerView Behavior on Swipe issue.

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.

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  }

upload_2022-2-18_12-52-7.png
 
Last edited:
Really?, Can nobody out there answer this? I've included a video capture of the issue for those that just don't get what I'm after. After swiping the button (which I've limited the dX so that it will only swipe so far) with the finger down, Recyclerview animates returning the button (because the swipe is never actually complete) to the position of the button edge. It's a bounce effect that just doesn't look professional to me. I've used, in the past, the SwipeReveal library and it does the same thing without the bouncing effect. Just want to know how to intercept this behavior. There is no override that I can find in the RecyclerView class.
 

Attachments

  • recyclerview issue.mp4
    402.9 KB · Views: 86
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones