Here is my solution, maybe this is not very cool, so if someone offers to share it with me.
public class BitmapDragAndDrop { BitmapDragAndDropListener listener; public BitmapDragAndDrop(BitmapDragAndDropListener listener) { this.listener = listener; } public boolean onTouch(View view, MotionEvent motionEvent) { switch (motionEvent.getAction()) { case MotionEvent.ACTION_DOWN: listener.onDragStart(motionEvent.getX(), motionEvent.getY()); view.invalidate(); return true; case MotionEvent.ACTION_MOVE: listener.onDragging(motionEvent.getX(), motionEvent.getY()); view.invalidate(); return true; case MotionEvent.ACTION_UP: listener.onDragEnd(listener.onDrop(motionEvent.getX(), motionEvent.getY())); view.invalidate(); return true; } return false; } public interface BitmapDragAndDropListener { void onDragStart(float x, float y); void onDragging(float x, float y); boolean onDrop(float x, float y); void onDragEnd(boolean isEntered); } } public class YourDrawer implements BitmapDragAndDrop.BitmapDragAndDropListener { Bitmap originalImage;
Ofc is not to copy and paste the code. You need to add your implementation to it.
In the main class (fragment or activity), you can run this code as follows:
YourDrawer yourDrawer = new YourDrawer(originalImage, objectBitmap); onTouchListener = new BitmapDragAndDrop(yourDrawer); imageView.setImageBitmap(yourDrawer.getDrawingBitmap())); imageView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent motionEvent) { if (onTouchListener != null) onTouchListener.onTouch(view, motionEvent); return false; } });
Solves only the drag problem, not rotation. But the basic idea will work even for rotation.
source share