拖放VideoView

时间:2016-01-12 10:06:55

标签: android drag-and-drop android-videoview

我正在创建一个Android应用程序,我需要在其中拖放视频视图。我能够做到这一点。但实际的问题是如何在拖动视频视图的同时创建拖动阴影?

1 个答案:

答案 0 :(得分:1)

尝试 -

    // Sets a long click listener for the ImageView

       img.setOnLongClickListener(new View.OnLongClickListener() {
       @Override
       public boolean onLongClick(View v) {
            ClipData.Item item = new ClipData.Item((CharSequence) v
             .getTag());
            String[] mimeTypes = { ClipDescription.MIMETYPE_TEXT_PLAIN };
            ClipData dragData = new ClipData(v.getTag().toString(),
              mimeTypes, item);

            // Instantiates the drag shadow builder.
            View.DragShadowBuilder myShadow = new DragShadowBuilder(img);

            // Starts the drag
            v.startDrag(dragData, // the data to be dragged
                        myShadow, // the drag shadow builder
                            null, // no need to use local data
                                0 // flags (not currently used, set to 0)
                       );
           return true;
           }
      });

       // Set the drag event listener for the View
       img.setOnDragListener(new OnDragListener() {
       @SuppressLint("NewApi")
       @Override
       public boolean onDrag(View v, DragEvent event) {
         switch (event.getAction()) {

         case DragEvent.ACTION_DRAG_STARTED:
         layoutParams = (RelativeLayout.LayoutParams) v
           .getLayoutParams();
         Log.d(msg, "Action is DragEvent.ACTION_DRAG_STARTED");
         break;

         case DragEvent.ACTION_DRAG_ENTERED:
         Log.d(msg, "Action is DragEvent.ACTION_DRAG_ENTERED");
         int x = (int) event.getX();
         int y = (int) event.getY();
         break;

         case DragEvent.ACTION_DRAG_EXITED:
         Log.d(msg, "Action is DragEvent.ACTION_DRAG_EXITED");
         x = (int) event.getX();
         y = (int) event.getY();
         layoutParams.leftMargin = x;
         layoutParams.topMargin = y;
         v.setLayoutParams(layoutParams);
         break;

         case DragEvent.ACTION_DRAG_LOCATION:
         Log.d(msg, "Action is DragEvent.ACTION_DRAG_LOCATION");
         x = (int) event.getX();
         y = (int) event.getY();
         break;

         case DragEvent.ACTION_DRAG_ENDED:
         Log.d(msg, "Action is DragEvent.ACTION_DRAG_ENDED");

         break;

         case DragEvent.ACTION_DROP:
         Log.d(msg, "ACTION_DROP event");

          break;

         default:
         break;
        }

        return true;

      }
    });
  }