开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜