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.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…