As @Ernir says, the API API does not receive DragShadow. But we know the location of the drag and drop so that we can draw it ourselves.
I am writing a simple and functional limited demo that you can download here .
It implements a custom ViewGroup called DragContainer. Use it to wrap the original root view in your xml layout.
<info.dourok.android.demo.DragContainer xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/root" android:layout_width="match_parent" android:layout_height="match_parent" > <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent"> </RelativeLayout> </info.dourok.android.demo.DragContainer>
call DragContainer # startDragChild to start dragging (see demo for more details):
In action:
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mDragContainer = (DragContainer) findViewById(R.id.root); View drag = mDragContainer.findViewById(R.id.drag); View drop = mDragContainer.findViewById(R.id.drop); drag.setTag(IMAGEVIEW_TAG); drag.setOnLongClickListener(new View.OnLongClickListener() { public boolean onLongClick(View v) { ClipData.Item item = new ClipData.Item((CharSequence) v .getTag()); ClipData dragData = new ClipData((CharSequence) v.getTag(), new String[] { ClipDescription.MIMETYPE_TEXT_PLAIN }, item); return mDragContainer.startDragChild(v, dragData,
You can also extend the DragContainer to draw a custom drag and drop shadow. This is an example of your requirement.
public class MyDragContainer extends DragContainer { public MyDragContainer(Context context, AttributeSet attrs) { this(context, attrs, 0); } public MyDragContainer(Context context) { super(context, null); } public MyDragContainer(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } int width; int height; Bitmap bitmap; @Override protected void onSetDragTarget(View v) { ImageView b = (ImageView) v; int x = Character.getNumericValue(b.getContentDescription().charAt(0)); int y = Character.getNumericValue(b.getContentDescription().charAt(1)); bitmap = InGameActivity.currentBoardState[x][y].getPicture(); width = bitmap.getWidth(); height = bitmap.getHeight(); } @Override protected void drawDragShadow(Canvas canvas) { Rect source = new Rect(0, 0, InGameActivity.chessSquareHeightWidth, InGameActivity.chessSquareHeightWidth); int w = InGameActivity.chessSquareHeightWidth; int h = InGameActivity.chessSquareHeightWidth; canvas.translate(getDragX() - w / 2, getDragY() - h / 2); canvas.drawBitmap(bitmap, null, source, null); } }
Hope this helps.