1

In a custom view, is there a way I can set the center of a drawable at a certain point on the canvas? (I don't want to deal with figuring out rectangular bounds for the drawable...)

Goo
  • 1,318
  • 1
  • 13
  • 31
ElectronAnt
  • 2,115
  • 7
  • 22
  • 39
  • Could you elaborate on what you're trying to accomplish? – Dan S Jun 29 '12 at 18:39
  • i just want to put a drawable on a screen and that drawable's center will be a point of my choosing. i know this can be done by setting bounds of the drawable, but i was wondering if i had to go through the trouble of that – ElectronAnt Jun 29 '12 at 18:42

1 Answers1

1

When you make the call to draw the Bitmap, draw it at a point with it's left and top attributes set to the position minus half the image's width and height, respectively. That will center it at the point you want.

IE.

canvas.drawBitmap(bitmap, xPos - bitmap.getWidth()/2, yPos - bitmap.getHeight()/2, new Paint());
Cruceo
  • 6,763
  • 2
  • 31
  • 52