문제

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