2012-08-01 91 views
1

我想使用dragShadowBuilder(视图视图)构造函数发送给它ImageView没有与我开始拖动的那个分离。 ImageView img = new ImageView(this); img.setbackgroundresource(R.drawable.icon); 为什么dragShadowBuilder在拖动过程中不显示它?为什么dragShadowBuilder不显示图像视图?

回答

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; 
    } 
}