bauerca / drag-sort-listview

Android ListView with drag and drop reordering.
3.2k stars 1.44k forks source link

Fling to remove sensitivity #106

Closed cucko closed 11 years ago

cucko commented 11 years ago

Is there a way to set/change 'fling to remove' sensitivity (probably velocity check). i have listview where both drag to sort, and fling to remove are enabled. but almost 50% it removes the items instead of scroll the list. thanks for your great library.

tauntz commented 11 years ago

https://github.com/bauerca/drag-sort-listview/pull/92 (https://github.com/tauntz/drag-sort-listview/commit/d635d6e46980f63866987c3059ae529fd93164c8) will probably resolve your issue

cucko commented 11 years ago

hm, its not that. my issue is that when user want to scroll the list, if he does a little angled move (not straight vertical), there is a very good chance that the motion is detected as fling/remove and removes the item instead of scrolling the list.

samma835 commented 11 years ago

@cucko , find the method in DragSortController.java, and try to make mTouchSlop BIGGER.

public DragSortController(DragSortListView dslv, int dragHandleId,
        int dragInitMode, int removeMode, int clickRemoveId,
        int flingHandleId) {
    super(dslv);
    mDslv = dslv;
    mDetector = new GestureDetector(dslv.getContext(), this);
    mFlingRemoveDetector = new GestureDetector(dslv.getContext(),
            mFlingRemoveListener);
    mFlingRemoveDetector.setIsLongpressEnabled(false);
    mTouchSlop = ViewConfiguration.get(dslv.getContext())
            .getScaledTouchSlop(); // ***to slow down the fling, you could set [mTouchSlop *= 4;]***
    mDragHandleId = dragHandleId;
    mClickRemoveId = clickRemoveId;
    mFlingHandleId = flingHandleId;
    setRemoveMode(removeMode);
    setDragInitMode(dragInitMode);
}
cucko commented 11 years ago

@bullda thank you, that's exactly what i was looking for.

rajuashok commented 11 years ago

FYI, I've found a good way to make the sensitivity better (at least for my uses). Basically I found that when I scroll the list sometimes the item would get flinged off. To solve this I adjusted the onScroll method in DragSortController to only fling if the horizontal difference was greater than 2 times the vertical difference. That is, make sure that the user isn't dragging more vertically than horizontally before flinging. Code:

} else if (mFlingHitPos != MISS) { if (Math.abs(x2 - x1) > mTouchSlop && mRemoveEnabled /\ I added this to the conditional */ && Math.abs(x2 - x1) > 2 \ Math.abs(y2 - y1)) { mIsRemoving = true; startDrag(mFlingHitPos, deltaX, deltaY); } else if (Math.abs(y2 - y1) > mTouchSlop) { mCanDrag = false; // if started to scroll the list then // don't allow sorting nor fling-removing } }

books1958 commented 10 years ago

Thank you very much. The solution is very useful.

jonathanmckay commented 10 years ago

That helped a lot!

Odaym commented 9 years ago

Black tiger's solution is best, thanks a lot