As question states. here is my dragshadowbuilder for reference. As you know, the shadow that is created when you drag is translucent. Is there anyway to make it opaque? (fully solid)
public class MyDragShadowBuilder extends View.DragShadowBuilder {
View view;
int width;
int height;
Bitmap bitmap;
public MyDragShadowBuilder(View v) {
super(v);
view = v;
ImageView b = (ImageView)view;
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
public void onDrawShadow(Canvas canvas) {
Rect source = new Rect(0, 0, InGameActivity.chessSquareHeightWidth, InGameActivity.chessSquareHeightWidth);
canvas.drawBitmap(bitmap, null, source, null);
}
@Override
public void onProvideShadowMetrics(Point shadowSize, Point touchPoint) {
shadowSize.set(InGameActivity.chessSquareHeightWidth, InGameActivity.chessSquareHeightWidth);
touchPoint.set(InGameActivity.chessSquareHeightWidth/2, InGameActivity.chessSquareHeightWidth/2);
}
}
EDIT: Here is my current onTouch code, I'll also provide a background of the app.
OnTouchListener myOnTouchListener = new OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent event) {
System.out.println(event.toString());
if (event.getAction() == MotionEvent.ACTION_DOWN) {
ImageView b = (ImageView)view;
int x = Character.getNumericValue(b.getContentDescription().charAt(0));
int y = Character.getNumericValue(b.getContentDescription().charAt(1));
if (!currentBoardState[x][y].isEmpty()) {
((ImageView)view).setImageBitmap(null);
DragShadowBuilder shadowBuilder = new MyDragShadowBuilder(view);
view.startDrag(null, shadowBuilder, view, 0);
}
moveChessPiece;
return true;
}
return false;
}
});
Ok so here's what you need to know. I am developing a chess application. I have an 8x8 GridLayout which I have named currentBoardState
. So currently I want to be able to drag the piece, which works, but I want the dragged piece to be opaque so the user gets the feeling that he/she is actually MOVING the piece rather than just clicking then clicking on a destination as I previously had it.
Dont know if someone is aware of it or not, We can achieve the same using flag DRAG_FLAG_OPAQUE, So the correspondind startDrag method will look like as below:
View.DragShadowBuilder dragShadowBuilder = new View.DragShadowBuilder(view);
view.startDrag(clipData, dragShadowBuilder, view, DRAG_FLAG_OPAQUE);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With