public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); DrawingView dv = new DrawingView(this); setContentView(dv); } class DrawingView extends View{ Bitmap bitmap; float x,y; public DrawingView(Context context) { super(context); bitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_launcher); } public boolean onTouchEvent(MotionEvent event) { switch(event.getAction()) { case MotionEvent.ACTION_DOWN: { } break; case MotionEvent.ACTION_MOVE: { x=(int)event.getX(); y=(int)event.getY(); invalidate(); } break; case MotionEvent.ACTION_UP: x=(int)event.getX(); y=(int)event.getY(); System.out.println(".................."+x+"......"+y); //x= 345 y=530 invalidate(); break; } return true; } @Override public void onDraw(Canvas canvas) { Paint paint = new Paint(); paint.setStyle(Paint.Style.FILL); paint.setColor(Color.CYAN); canvas.drawBitmap(bitmap, x, y, paint); //originally bitmap draw at x=o and y=0 } } }
In a star raster image, draw at x = 0 and y = 0; When dragging x and y, the changes cause inavlidate to update the drate. When you touch up, display the bitmap in the draggable position x and y and call invalidate to update the draw.
A bitmap drawn at x = 0 y = 0. when dragging // x = 345 y = 530. The resulting click is anchored.
You need to make sure your image does not seem to exit the screen at the edges of the screen. Check if x is within the width of the screen - bitmap and y is less than shielding - bitmap. I did not include these conditions in the code.

EDIT:
setContentView(R.layout.main); LinearLayout ll = (LinearLayout) findViewById(R.id.ll); DrawingView dv= new DrawingView(this); ll.addView(dv);
source share