我正在尝试使用dragShadowBuilder(View视图)构造函数发送给它ImageView没有与我开始拖延的那个相关联。 ImageView img = new ImageView(this); img.setbackgroundresource(R.drawable.icon); 为什么dragShadowBuilder在拖动过程中不会显示它?
答案 0 :(得分:0)
我认为问题是ImageView在添加到布局之前不会被绘制。 我通过使用扩展的ShadowBuilder绘制一个Bitmap解决了这个问题:
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;
}
}