Question

I want to move each items of my listview by drag. I set OnTouch for listview and drag and drop items by set left and right margin. This is my procedure:

private void setLastViewDistance(float distanceX, View lastView) {
    if (lastView.getLayoutParams().getClass() == AbsListView.LayoutParams.class)
        lastView = ((ViewGroup) lastView).getChildAt(0);

    LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) lastView.getLayoutParams();
    lp.leftMargin = (int) distanceX;
    lp.rightMargin = -(int) distanceX;
    lastView.setLayoutParams(lp);
    lastView.postInvalidate();
}

But this code is slow motion in phone device. is any idea like setLeft(not work) setRight(not work) or...? thank you!

Was it helpful?

Solution

It looks like this question is nearly the same as yours: android drag view smooth

Drag and drop in listview is somehow complicated... But there's a library for that (https://github.com/bauerca/drag-sort-listview) or you can read this drag and drop tutorial: http://www.vogella.com/articles/AndroidDragAndDrop/article.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top