我在方法中放了一个log.d,它从不报告。 Game的run()方法被执行,但我在继续之前等待surfaceCreated方法返回。
注意:游戏是一个线程和 TouchPanel扩展了SurfaceView实现的SurfaceHolder.Callback
private final void runGame() {
savedPos = 0;
resumeGame();
touchPanel = (TouchPanel)findViewById(com.mysite.mygame.R.id.touchPanel);
touchPanel.setMinimumHeight(displayWidth);
touchPanel.setParams(this, writeLock, gemSize9, gemSize12, marg);
textUpdate = new TextUpdate(this, d);
gm = new Game(tok9, tok12, m, d, this, textHandler, textUpdate, touchPanel, marg, gemSize9, gemSize12, readLock, writeLock);
initBitmaps();
gm.start();
}
private final void resumeGame() {
loadBGMusic();
layout = Layout.GAME;
setContentView(com.mysite.mygame.R.layout.game);
writeLock.lock(); try { paused = false; } finally { writeLock.unlock(); }
}
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/rel"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/backrepeat"
android:keepScreenOn="true"
>
<com.mysite.mygame.TouchPanel
android:id="@+id/touchPanel"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:clickable="true"
android:focusableInTouchMode="true"
/>
</RelativeLayout>
public TouchPanel(Context context, AttributeSet attrs) {
super(context, attrs);
getHolder().addCallback(this);
}
答案 0 :(得分:0)
我明白了。
@id/touchPanel
应该有
android:layout_height != 0
和
android:layout_width != 0
用于在SurfaceView中创建Surface。