如問題所述。這裏是我的dragshadowbuilder供參考。如您所知,拖動時創建的陰影是半透明的。無論如何要讓它變得不透明嗎? (完全固體)是否有可能使陰影不透明?
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);
}
}
編輯︰這是我目前的onTouch代碼,我也會提供應用程序的背景。
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;
}
});
好的,這是你需要知道的。我正在開發一個國際象棋應用程序。我有一個名爲currentBoardState
的8x8 GridLayout。所以目前我希望能夠拖動該作品,但是我希望被拖動的作品是不透明的,這樣用戶就可以感覺到他/她實際上是MOVING作品,而不僅僅是點擊然後點擊目的地正如我以前所做的那樣。
工作,你的意思是你的看法是半透明的,但你需要它拖影是不透明的? – DouO