Your question is too general to be sure what you need, but I think you copied this from a drag-and-drop white paper tutorial , and in this case, note that when you create an instance of the shadow drag builder, you execute it with the class MyDragShadowBuilderthat defined below.
The whole class may look like this:
public class MainActivity extends ActionBarActivity {
private static final String IMAGEVIEW_TAG = "icon bitmap";
ImageView imageView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageView = (ImageView) findViewById(R.id.image_to_be_dragged);
imageView.setImageResource(R.mipmap.ic_launcher);
imageView.setTag(IMAGEVIEW_TAG);
imageView.setOnLongClickListener(new View.OnLongClickListener() {
public boolean onLongClick(View v) {
ClipData.Item item = new ClipData.Item((String)v.getTag());
ClipData dragData = new ClipData((CharSequence) v.getTag(), new String[]{ClipDescription.MIMETYPE_TEXT_PLAIN}, item);
View.DragShadowBuilder myShadow = new MyDragShadowBuilder(imageView);
v.startDrag(dragData,
myShadow,
null,
0
);
return true;
}
});
}
private static class MyDragShadowBuilder extends View.DragShadowBuilder {
private static Drawable shadow;
public MyDragShadowBuilder(View v) {
super(v);
shadow = new ColorDrawable(Color.LTGRAY);
}
@Override
public void onProvideShadowMetrics(Point size, Point touch) {
int width, height;
width = getView().getWidth()/2;
height = getView().getHeight()/2;
shadow.setBounds(0,0,width,height);
size.set(width,height);
touch.set(width/2,height/2);
}
@Override
public void onDrawShadow(Canvas canvas) {
shadow.draw(canvas);
}
}
}
Edit:
Now I think that perhaps the problem for the seeker was simpler, and he just needed to write the following:
View.DragShadowBuilder myShadow = new View.DragShadowBuilder(ima);
therefore, a default shadow is created. I apologizeView.
source
share