1
我想使用dragShadowBuilder(視圖視圖)構造函數發送給它ImageView沒有與我開始拖動的那個分離。 ImageView img = new ImageView(this); img.setbackgroundresource(R.drawable.icon); 爲什麼dragShadowBuilder在拖動過程中不顯示它?爲什麼dragShadowBuilder不顯示圖像視圖?
我想使用dragShadowBuilder(視圖視圖)構造函數發送給它ImageView沒有與我開始拖動的那個分離。 ImageView img = new ImageView(this); img.setbackgroundresource(R.drawable.icon); 爲什麼dragShadowBuilder在拖動過程中不顯示它?爲什麼dragShadowBuilder不顯示圖像視圖?
我認爲這個問題是,ImageView不會被繪製直到它被添加到佈局。 我通過使用擴展的ShadowBuilder繪製位圖來解決此問題:
public class LJDragShadowBuilder extends View.DragShadowBuilder {
private Bitmap image; // image to draw as a drag shadow
public LJDragShadowBuilder(Bitmap _image) {
super();
image = _image;
}
public void onDrawShadow(Canvas canvas)
{
canvas.drawBitmap(image, 0, 0, null);
}
public void onProvideShadowMetrics(Point shadowSize, Point shadowTouchPoint)
{
shadowSize.x = image.getWidth();
shadowSize.y = image.getHeight();
shadowTouchPoint.x = shadowSize.x/2;
shadowTouchPoint.y = shadowSize.y/2;
}
}