I am on Android Lollipop (minSdk=21), and want to implement moving a Floating Action Button around with a dragging gesture. The button is a custom subclass of ImageButton, the code is described here so I won't repeat it: Define default values for layout_width and layout_height properties for a subclass in a style
For dragging, I use the way described here: http://developer.android.com/guide/topics/ui/drag-drop.html. Here is what my code looks like:
favoriteButton.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
v.startDrag(null, new View.DragShadowBuilder(v), null, 0);
return true;
}
});
findViewById(R.id.test_main_layout).setOnDragListener(new View.OnDragListener() {
@Override
public boolean onDrag(View v, DragEvent event) {
switch (event.getAction()) {
case DragEvent.ACTION_DRAG_ENTERED:
favoriteButton.setVisibility(View.INVISIBLE);
break;
case DragEvent.ACTION_DROP:
favoriteButton.setX(event.getX() - favoriteButton.getWidth() / 2);
favoriteButton.setY(event.getY() - favoriteButton.getHeight() / 2);
favoriteButton.setVisibility(View.VISIBLE);
break;
}
return true;
}
});
Generally, it works, but the problem is the 'drag shadow': it is square. For this reason or the other, it doesn't respect the oval outline of the FAB.
How can I make it behave correctly?