Android 拖放时列表不能正确滚动

Android 拖放时列表不能正确滚动,android,listview,Android,Listview,我可以剪辑Bye,但当我想拖动列表视图时,无法正确滚动 这是在列表视图上执行的事件。我们首先通过点对点的方式得到项目的位置,然后根据位置移动列表 public boolean onDrag(View v, DragEvent event) { final int action = event.getAction(); switch (action) { case DragEve

我可以剪辑Bye,但当我想拖动列表视图时,无法正确滚动

这是在列表视图上执行的事件。我们首先通过点对点的方式得到项目的位置,然后根据位置移动列表

public boolean onDrag(View v, DragEvent event)
        {
            final int action = event.getAction();
            switch (action) {          

                case DragEvent.ACTION_DRAG_LOCATION:

  //  get position of the selected item in the list 
                    int position = pointToPosition((int) event.getX(), (int) event.getY());

 //  method to move list up and down 
                    moveListViewUpOrDown(position);

                    return true;            
                default:
                    break;
            }
            return false;
        }



     private void moveListViewUpOrDown(int position) {
   // get first visible position of listview
            int firstPosition = getFirstVisiblePosition();

 // get last visible position of listview   
            int lastPosition = getLastVisiblePosition();        

  // to scroll listview up   
            if ((position == firstPosition || position == firstPosition + 1) && firstPosition != 0) {
                smoothScrollToPosition(position - 1);
            }

  // to scroll listview down   
            if ((position == lastPosition || position == lastPosition - 1) && lastPosition != getCount() - 1) {
                smoothScrollToPosition(position + 1);
            }
        }

写清洁剂会增加你得到答案的机会写清洁剂会增加你得到答案的机会