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!

有帮助吗?

解决方案

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top