question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Swipe item too sensitive, it is hard to do onClick

See original GitHub issue

I use a Recycler view where user can do click, long click and swipe. I don’t have any problem with long click and swipe, but when I try to do a click, four out five times, I end up getting a swipe gesture instead a click.

I tried app:minDistRequestDisallowParent=20dp but I do not notice any improvement. Also I tried setMinFlingVelocity without success.

Any idea about what I’m doing wrong? Thanks.

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:15

github_iconTop GitHub Comments

11reactions
qihongbocommented, Jul 5, 2017

private float mX = -1,mY = -1; @Override public boolean onInterceptTouchEvent(MotionEvent ev) {

    if(isDragLocked()){
        return super.onInterceptTouchEvent(ev);
    }

    mGestureDetector.onTouchEvent(ev);
    mDragHelper.processTouchEvent(ev);

    switch (ev.getAction()) {
        case MotionEvent.ACTION_DOWN: {
            mX = ev.getRawX();
            mY = ev.getRawY();
        }
    }

    if(inMainView(ev)){
        boolean in = isInTouchSlop(ev);
        if(in){
            return false;
        }
    }

    boolean settling = mDragHelper.getViewDragState() == ViewDragHelper.STATE_SETTLING;
    boolean idleAfterScrolled = mDragHelper.getViewDragState() == ViewDragHelper.STATE_IDLE
            && mIsScrolling;

    return settling || idleAfterScrolled;
}

private boolean inMainView(MotionEvent ev){
    float x = ev.getX();
    float y = ev.getY();
    return x >= mMainView.getLeft() && x <= mMainView.getRight() && y >= mMainView.getTop() && y <= mMainView.getBottom();
}

private boolean isInTouchSlop(MotionEvent ev){
    boolean in = false;
    if(getDragEdge() == DRAG_EDGE_LEFT || getDragEdge() == DRAG_EDGE_RIGHT){
        float distanceX = Math.abs(ev.getRawX()-mX);
        if(distanceX < mDragHelper.getTouchSlop()){
            in = true;
        }
    }else{
        float distanceY = Math.abs(ev.getRawY()-mY);
        if(distanceY < mDragHelper.getTouchSlop()){
            in = true;
        }
    }

    return in;
}

This is my changed code. good luck.

2reactions
tanakasamacommented, Jun 27, 2017

I guess people should use https://github.com/daimajia/AndroidSwipeLayout . This repos have many issues with android version and devices. And this is not maintain now.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Swipe delete on Recycleview is very sensitive - Stack Overflow
The problem is that the action is very sensitive - When you click or drag a little bit the card it do the...
Read more >
onclick function too sensitive - Genuitec
The workaround is to use phoneui.alert() which runs asynchronously in native apps or maybe put your javascript alert in a setTimeout(). I revised...
Read more >
Well-controlled scrolling with CSS Scroll Snap - web.dev
CSS Scroll Snap allows web developers to create well-controlled scroll experiences by declaring scroll snapping positions.
Read more >
Pressable - React Native
How it works​ ... On an element wrapped by Pressable : ... After pressing onPressIn , one of two things will happen: ......
Read more >
Handling swipe and click with JavaScript - Jon Gjengset
These are what break your onclick handler (or href), since they tell the browser not to do whatever it would normally have done...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found