0

I have a Game class which extends Activity:

public class Game extends Activity
...

in which I'm setting content view to XML layout, and just after that switching to my GamePanel class like this:

setContentView(R.layout.game_layout);
setContentView(new GamePanel(this));

In GamePanel class I need to update and draw objects on my layout game_layout. But my game_layout isn't showing because of switching to GamePanel.

How do I keep displaying first layout view and switch to class Gamepanel?

public class GamePanel extends SurfaceView implements SurfaceHolder.Callback
...
johnyX
  • 101
  • 1
  • 7
  • Is the question to put the Gamepanel inside the game layout like a smaller part of it? Or it isn't displaying at all? – dave Mar 30 '16 at 16:11
  • 1
    I think you need fragments: http://developer.android.com/intl/es/guide/components/fragments.html – Miguel Benitez Mar 30 '16 at 16:14
  • Gamepanel is overlaping whole screen (although I didn't set it any bg or something like that). So it's "displaying" (working). I need it to display over first layout, but transparently, if you know what I mean (just draw views on it over first layout). – johnyX Mar 30 '16 at 16:15
  • 1
    setContentView means you are setting that as your Activity's content view. When you are calling `setContentView(new GamePanel(this))` you are changing the content that you previously set with `setContentView(R.layout.game_layout)`. If you want the `GamePanel` view to overlap the `R.layout.game_layout` not override it, you need to create the GamePanel view and add it to your contentView. Something like `this.findViewById(android.R.id.content).addView(new GamePanel(this))` – zgc7009 Mar 30 '16 at 16:17

2 Answers2

0

If you want to display both views at the same time, try to add dinamically the GamePanel to the main layout view.

You have an example here Add view dinamically

Community
  • 1
  • 1
Jorge
  • 1,136
  • 9
  • 15
0

In your code

setContentView(R.layout.game_layout);
setContentView(new GamePanel(this));

It overwrites game_layout by GamePanel. To make game_layout is the background you need to setup the GamePanel inside game_layout, i guest it is from game_layout.xml

VinhNT
  • 1,091
  • 8
  • 13