0
我試圖在Galaxy Nexus的屏幕中央畫一個圓圈,更像是一次學習體驗。要做到這一點,我使用這行代碼:Galaxy Nexus,繪製居中圓
canvas.drawCircle(canvas.getWidth()/2, canvas.getHeight()/2, 40, paint);
問題是我只能看到屏幕右下角的四分之一的圓圈。我已經在我的Galaxy SII上嘗試了完全相同的代碼,並在屏幕中間繪製了圓圈。我檢查了getwidth和getheight的值,它報告640x1052,但在屏幕上,右下像素的座標是320約450(不包括屏幕上的按鈕)。
這是怎麼回事?應用程序的一部分可以設置決議或什麼?
我已經在下面列出了我的全部活動。
package com.helloworld;
import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
public class ShapeTest extends Activity {
class RenderView extends View {
Paint paint;
public RenderView(Context context) {
super(context);
paint = new Paint();
}
protected void onDraw(Canvas canvas) {
Context context = getApplicationContext();
canvas.drawRGB(255, 255, 255);
paint.setColor(Color.RED);
canvas.drawLine(0, 0, this.getWidth()-1, this.getHeight()-1, paint);
paint.setStyle(Style.STROKE);
paint.setColor(0xff00ff00);
canvas.drawCircle(canvas.getWidth()/2, canvas.getHeight()/2, 40, paint);
paint.setStyle(Style.FILL);
paint.setColor(0x770000ff);
canvas.drawRect(100, 100, 200, 200, paint);
}
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(new RenderView(this));
}
}
謝謝,是的,它的確如此。這似乎修復了它。爲什麼它會在SII而不是Galaxy Nexus上運行? – DNN 2012-03-26 10:50:38