一直在尋找一些教程繪製使用SurfaceView帆布,但顯示出來的僅僅是一個黑色的背景。SurfaceView實現Runnable - 線程沒有啓動
public class FighterActivity extends Activity implements OnTouchListener {
/** Called when the activity is first created. */
SurfaceController surface;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
surface = new SurfaceController(this);
surface.setOnTouchListener(this);
setContentView(surface);
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
surface.pause();
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
surface.resume();
}
public class SurfaceController extends SurfaceView implements Runnable{
Thread thread = null;
SurfaceHolder holder;
public SurfaceController(Context context) {
super(context);
// TODO Auto-generated constructor stub
holder = getHolder();
System.out.println("HERE");
}
public void run() {
// TODO Auto-generated method stub
System.out.println("Hello World2");
while(true){
if(!holder.getSurface().isValid()){
System.out.println("NOT VALID");
continue;
}
System.out.println("VALID!");
Canvas can = holder.lockCanvas();
can.drawARGB(255, 150, 150, 0);
holder.unlockCanvasAndPost(can);
}
}
public void pause(){
}
public void resume(){
}
}
public boolean onTouch(View view, MotionEvent me) {
// TODO Auto-generated method stub
return false;
}
}
它得到System.out.println(「HERE」);這裏打印出來,但僅此而已happends,換句話說線程不上手,因爲「你好World2」不能打印,是什麼問題?
感謝所有幫助
你沒有顯示你是如何使用*它的。通過它的聲音,我們在調用構造函數,但是然後呢? – 2012-03-23 08:10:31
添加的代碼現在 – Araw 2012-03-23 08:17:19