如何在不同的Recycler视图之间拖放项目并水平自动滚动

时间:2018-12-17 05:18:53

标签: android android-studio android-recyclerview drag-and-drop autoscroll

我想在不同的回收站视图之间拖放项目,并在项目向左或向右移动时使水平滚动自动滚动。

这是我的代码,但无法正常工作

mScrollDistance = scrollView.getScrollY();
int y = Math.round(v.getX())+Math.round(event.getX());
        int translatedY = y ;
        Log.i("translated",""+translatedY+" "+ mScrollDistance+" "+y);
        int threshold =50 ;

        if (translatedY < 200) {

            scrollView.smoothScrollBy(-15, 0);
        }
        // make a autoscrolling down due y has passed the 500 px border
        if (translatedY + threshold > 500) {

            scrollView.smoothScrollBy(15, 0);
        }

1 个答案:

答案 0 :(得分:0)

尝试此代码:

if (translatedY < threshold) {
                            // make a scroll up by 30 px
                            scrollView.smoothScrollBy(0, -30);

                        } else
                            // make a autoscrolling down due y has passed the 500 px border
                            if (translatedY + threshold > 500) {
                                // make a scroll down by 30 px
                                scrollView.smoothScrollBy(0, 30);
                            }