恢复surfaceView活动

时间:2011-11-11 21:11:07

标签: android button android-activity surfaceview

所以我有一个带按钮的游戏菜单,开始游戏按钮用一个客户surfaceView改变了contentView,我需要让游戏在最小化后用按钮显示菜单然后恢复(在视图改变之后)一个surfaceView)所以这是我的代码:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);

    setContentView(R.layout.main);
    contButton = (Button) findViewById(R.id.cont);
    contButton
            .setVisibility(showContButton ? View.VISIBLE : View.INVISIBLE);

}

public void startGame(View theButton) {
    gameView = new GameView(this);
    setContentView(gameView);
    gameView.resume();
}

public void onPause() {
    super.onPause();
    if (gameView != null)
        gameView.pause();

    // if (isFinishing())
    // screen.dispose();

}

public void onResume() {
    super.onResume();
}

如果我改变onResume:

,我可以得到我需要的东西
public void onResume() {
    super.onResume();
    if (gameView != null) showContButton = true;
    setContentView(R.layout.main);
    setContentView(R.layout.main);
    contButton = (Button) findViewById(R.id.cont);
    contButton
            .setVisibility(showContButton ? View.VISIBLE : View.INVISIBLE);


}

但我认为这是一个可怕的解决方案,任何人都可以提出想法吗?

0 个答案:

没有答案