Android 拖动视图时在回收器视图中自动滚动

Android 拖动视图时在回收器视图中自动滚动,android,android-recyclerview,Android,Android Recyclerview,我在约束布局中有一个回收器视图。 我可以在“回收器”视图中拖放项目,但每当我拖动项目时,如果我到达屏幕的最底部或顶部,则“回收器”视图不会自动滚动 我尝试过但失败的事情: 我在某个地方读到应该禁用recyclerview的nestedscrollview 我尝试在“回收器”视图上设置一个拖动侦听器: // @Override // public boolean onDrag(View v, DragEvent event) { //

我在约束布局中有一个回收器视图。 我可以在“回收器”视图中拖放项目,但每当我拖动项目时,如果我到达屏幕的最底部或顶部,则“回收器”视图不会自动滚动

我尝试过但失败的事情:

我在某个地方读到应该禁用recyclerview的nestedscrollview

我尝试在“回收器”视图上设置一个拖动侦听器:

//            @Override
//            public boolean onDrag(View v, DragEvent event) {
//                if (event.getAction()== DragEvent.ACTION_DRAG_LOCATION) {
//
//                    RecyclerView.Adapter adapter =  recyclerView.getAdapter();
//                    int y = Math.round(event.getY());
//
//                    int translatedY = y - recyclerView.computeHorizontalScrollExtent();
//
//                    int threshold = 50;
//                    // make a scrolling up due the y has passed the threshold
//                    if (translatedY < threshold) {
//                        // make a scroll up by 30 px
//                        recyclerView.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
//                            recyclerView.smoothScrollBy(0, 30);
//                        }
//                return true;
//                }else {
//                    return false;
//                }
//
//            }
//        });
/@覆盖
//公共布尔onDrag(视图v,DrageEvent事件){
//if(event.getAction()==DragEvent.ACTION\u拖动位置){
//
//RecyclerView.Adapter=RecyclerView.getAdapter();
//int y=Math.round(event.getY());
//
//int translatedY=y-recyclerView.computeHorizontalScrollExtent();
//
//int阈值=50;
////由于y已超过阈值,请向上滚动
//if(translatedY<阈值){
////向上滚动30像素
//recyclerView.smoothScrollBy(0,-30);
//
//}其他
////由于y已通过500像素边界,进行自动向下滚动
//如果(平移Y+阈值>500){
////向下滚动30像素
//recyclerView.smoothScrollBy(0,30);
//                        }
//返回true;
//}其他{
//返回false;
//                }
//
//            }
//        });