2016-12-13 2 views
0

私はOnDragListenerを使って画像をドラッグアンドドロップしています。私は画像移動機能を実装するためにMOTIONEVENT.ACTION_MOVEを持っています。アクションの移動の特定のポイントで、私はドラッグを終了し、そのシャドウを削除したい。ドラッグイベントでアクションを設定することは可能ですか?指を離す前に、私はドロップイベントを呼びたいと思う。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

関連する問題