如何使用Canvas将图像放置在屏幕的中央

问题描述

|| 我正在使用画布在Android中显示图像。我希望此图像能占据屏幕的中心,而不管屏幕的大小。所以我怎么能做到这一点。 这是我尝试过的代码段,也请让我知道您的想法。
@Override
        protected void onDraw(Canvas canvas) {
        ..........
            ..........
            sampleImage.draw(canvas,getWidth(),getHeight()); // This moves the image to right end of the view.
            ..........
            ..........
任何帮助都将受到高度赞赏。 谢谢。     

解决方法

sampleImage.draw(
      canvas,getWidth()/2 - imageWidth/2,getHeight()/2 - imageHeight/2
); 
;)