Android drag and drop issue not displaying

有些话、适合烂在心里 提交于 2019-12-05 19:24:09

Finally I solved this myself. I added this method:

 private boolean dropEventNotHandled(DragEvent dragEvent) {
            return !dragEvent.getResult();
}

and added this:

 case DragEvent.ACTION_DRAG_ENDED:
           if (dropEventNotHandled(event)) 
              view.setVisibility(View.VISIBLE);
        break;

So when you start dragging - motionEvent.getAction() == MotionEvent.ACTION_DOWN - you execute view.setVisibility(View.INVISIBLE);

But when you stop dragging, you don't do anything to the view. So I guess your view object is still invisible. Add a similar conditional statement to flip the visibility back to visible when the drag finishes.

Off the top of my head, assuming that MotionEvent.ACTION_UP is the end of a drag event, add the following after the first if block in your onTouch method

else if (motionEvent.getAction() == MotionEvent.ACTION_UP) {
    view.setVisibility(View.VISIBLE);
    return true
}

Keep the final "else" block as well.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!