2016-12-13 11 views
0

이미지를 드래그 앤 드롭하려면 OnDragListener을 사용하고 있습니다. 나는 이미지 이동 기능을 구현하는 MOTIONEVENT.ACTION_MOVE 있습니다. 액션 이동의 특정 시점에서 드래그를 끝내고 그림자를 제거하고 싶습니다. 드래그 이벤트에서 액션을 설정할 수 있습니까? 손가락을 떼기 전에 drop 이벤트에 전화하고 싶습니다.DragEvent에서 액션을 설정하는 방법

switch(event.getAction()) { 

     case MotionEvent.ACTION_MOVE: 
      //here i want to remove shadow and stop dragging 
      break; 
     case DragEvent.ACTION_DROP:break; 
    } 
+0

변경 배경을 참조하십시오. – Vinodh

+0

** Listview ** 또는 ** Recyclerview **를 사용하고 있습니까? – Lovekesh

답변

0

클래스/조각에 OnDragListener를 구현할 수 있습니다. 자세한 내용은

  class MyDrag implements OnDragListener { 
      Drawable image = getResources().getDrawable(
          R.drawable.shape_droptarget); 

      @Override 
      public boolean onDrag(View v, DragEvent event) { 
        int action = event.getAction(); 
        switch (event.getAction()) { 
        case DragEvent.ACTION_DRAG_STARTED: 
          // Signals the start of a drag and drop operation 
          break; 
        case DragEvent.ACTION_DRAG_ENTERED: 
          //Signals to a View that the drag point has entered the bounding box of the View 
          v.setBackgroundDrawable(image); 
          break; 
        case DragEvent.ACTION_DRAG_EXITED: 
          //Signals that the user has moved the drag shadow out of the bounding box of the View or into a descendant view that can accept the data. 
          v.setBackgroundDrawable(image); 
          break; 
        case DragEvent.ACTION_DROP: 
          // Signals to a View that the user has released the drag shadow, and the drag point is within the bounding box of the View and not within a descendant view that can accept the data. 
          View view = (View) event.getLocalState(); 
          ViewGroup owner = (ViewGroup) view.getParent(); 
          owner.removeView(view); 
          LinearLayout container = (LinearLayout) v; 
          container.addView(view); 
          view.setVisibility(View.VISIBLE); 
          break; 
        case DragEvent.ACTION_DRAG_ENDED: 
          //Signals to a View that the drag and drop operation has concluded. 
          v.setBackgroundDrawable(image); 
        default: 
          break; 
        } 
        return true; 
      } 
    } 

런타임에 따라 여기 Drag and Drop

+0

예. 나는 같은 것을 사용하고 있습니다. 하지만 나는 또한 MotionEvent.ACTION_MOVE를 사용하여 이동을 추적합니다. 그래서 Action_move의 특정 지점에서 나는 DragEvent.ACTION_DROP를 시작하려고합니다. – android

+0

https://developer.android.com/guide/topics/ui/drag-drop.html을 참조하십시오. – sasikumar