开发者

How to Place a Image at the center of Screen using Canvas

开发者 https://www.devze.com 2023-02-25 16:29 出处:网络
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.

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

;)

0

精彩评论

暂无评论...
验证码 换一张
取 消