-2
我正在製作一個簡單的繪畫應用程序,這是我第一次使用畫布。我已經在我的佈局xml中使用了SurfaceView,並且該ID是正確的。無論如何,這裏是我的代碼:Android帆布不顯示
package com.example.paint;
import android.app.Activity;
import android.graphics.Canvas;
import android.os.Bundle;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
public class Paint extends Activity {
/** Called when the activity is first created. */
SurfaceView v;
SurfaceHolder holder;
Canvas c;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
v = (SurfaceView) findViewById(R.id.svDraw);
holder = v.getHolder();
while (true) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (!holder.getSurface().isValid())
continue;
c = holder.lockCanvas();
c.drawARGB(255, 0, 255, 0);
holder.unlockCanvasAndPost(c);
}
}
}
謝謝。
又有什麼問題屬於? – 2012-04-27 22:51:36
你的應用程序將ANR,因爲你永遠在'onCreate'中阻止UI線程。查看[LunarLander](http://developer.android.com/resources/samples/LunarLander/src/com/example/android/lunarlander/index.html)Api演示,瞭解它的工作原理。 – zapl 2012-04-27 22:58:27