我正在尝试使用 dragShadowBuilder(View view) 构造函数发送给它的 ImageView 与我开始拖动的那个不相关。ImageView img=new ImageView(this); img.setbackgroundresource(R.drawable.icon); 为什么 dragShadowBuilder 在拖动过程中不显示它?
问问题
1059 次
1 回答
0
我认为问题在于 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;
}
}
于 2013-01-31T02:03:51.577 回答