【问题标题】:How to drag and drop items between different Recycler views and auto scroll horizontally如何在不同的 Recycler 视图之间拖放项目并自动水平滚动
【发布时间】:2018-12-17 05:18:52
【问题描述】:

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

这是我的代码,但它没有按预期工作

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);
        }

【问题讨论】:

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


    【解决方案1】:

    试试这个代码:

    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);
                                }
    

    【讨论】:

      猜你喜欢
      • 2020-03-21
      • 2011-11-18
      • 2019-06-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多