سؤال

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