3

Well, I'm making a game that uses a class that extends from SurfaceView to represent the game screen, but it works with buttons, so I'm defining the "buttons panel" on xml and then adding the "GameView" to the LinearLayout, that contains all the stuff, programatically and bringing the "buttons panel" to front, just like this:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    LinearLayout rl1 = (LinearLayout)findViewById(R.id.rl1);
    rl1.addView(new GameView(this));
    SquareLayout sq1 = (SquareLayout)findViewById(R.id.square);
    //the control buttons are in another custom layout called "SquareLayout"
    sq1.bringToFront();
}

The problem here is that i want the layout that contains the game buttons(the SquareLayout) to fill the half of the height of the RelativeLayout(the activity is set to landscape), i get this morphing the RelativeLayout to a vertical LinearLayout, adding another SquareLayout, and setting both weight's properties to 1, and it's like this:

enter image description here

The problem now is that "bringToFront();" method does not work on LinearLayout, so I can't modify the z of the buttons panel after adding the gameview, so my question is if there's a way to make the buttons panel just like is on the image on a RelativeLayout or a similar method like "bringToFront()" that works on LinearLayout.

fadden
  • 51,356
  • 5
  • 116
  • 166
  • possible duplicate of [how to use z-index in android](http://stackoverflow.com/questions/8079500/how-to-use-z-index-in-android) – CommonSenseCode Jul 20 '15 at 00:02

1 Answers1

0

Try to invoke the method bringChildToFront(View) on your LinearLayout http://developer.android.com/reference/android/view/ViewGroup.html#bringChildToFront(android.view.View). The parameter will be the view you want to display on top of its siblings.

Chris Fox
  • 76
  • 1
  • 6