I am using the canvas to display an image in Android. I want this image to occupy the center of the screen irrespective of the sizes of the screen. So how could i achieve it.
This is the snippet that i tried with, Please let me know your ideas too.
@Override
protected void onDraw(Canvas canvas) {
...开发者_Go百科.......
..........
sampleImage.draw(canvas,getWidth(),getHeight()); // This moves the image to right end of the view.
..........
..........
Any kind of help is highly appreciated.
Thanks.
sampleImage.draw(
canvas,
getWidth()/2 - imageWidth/2,
getHeight()/2 - imageHeight/2
);
;)
精彩评论