2011-11-15 61 views

回答

16

下面的代碼可用於獲取屏幕的寬度和高度。

int width = this.getWidth(); 
int height = this.getHeight(); 

要繪製圓在畫面的中間,你可以撥打:

Canvas.drawCircle(width/2, height/2) 
3

假設你正在擴展視圖類:

int CentreX = (this.getWidth()/2); 
int CentreY = (this.getHeight()/2); 
3

你可以畫集中到屏幕上像這樣的循環:

Display disp = ((WindowManager)this.getContext().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); 
canvas.drawCircle(disp.getWidth()/2, disp.getHeight()/2, radius, paint); 
+0

'顯示#的getWidth() '和'Display#getHeight()'已棄用。 –