문제

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...)

도움이 되었습니까?

해결책

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());
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top