Calling bringChildToFront () method from surface screen in frameLayout not working?

Is it possible to add a surfaceView child to frameLayout and then call the bringChildToFront () method to call another child in front of the View?

This is my first Android app that I made, so please let me know if my setup makes sense or if I am doing the wrong things in the wrong places.

  • I have one action that has a FrameLayout.
  • I have 2 views (called pauseMenuView and mainMenuView) that are just views that have 4 buttons. These menu buttons are handled by overriding onClick () inside my activity.
  • I have a third custom view (called gameView) that extends SurfaceView. Here, I am now processing almost everything related to my gameplay (handling touch events, drawing graphics, animation, collision detection). I have a separate thread for managing state (paused, without waiting, etc.) And the frame rate in the game.

So, basically, during the game, I have a pause icon in the upper left corner of the screen. I try to make it so that when they touch this icon, my gameView onTouchEvent calls the bringChildToFront (pauseMenuView) function to display the pause menu. However, for the time being, when I call the bringChildToFront () or bringToFront () method, nothing happens as if they were not affected. My gameView is still visible.

Here is the relevant code from my activity:

public static final int INDEX_MAIN_MENU_VIEW = 0; public static final int INDEX_PAUSE_MENU_VIEW = 1; public static final int INDEX_GAMEVIEW_VIEW = 2; fl = new FrameLayout(this); LayoutParams lp = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); fl.setLayoutParams(lp); mainMenuView = View.inflate(this, R.layout.main_menu,null); pauseMenuView = View.inflate(this, R.layout.pause_menu, null); fl.addView(mainMenuView, INDEX_MAIN_MENU_VIEW); fl.addView(pauseMenuView, INDEX_PAUSE_MENU_VIEW); setContentView(fl); View onePlayerButton = findViewById(R.id.onePlayer_button); onePlayerButton.setOnClickListener(this); /* then i set up a bunch of pauseMenu and mainMenu buttons the same way, so I won't put them here */ fl.bringChildToFront(mainMenuView); 

So, when the application starts, mainMenuView is brought to the fore, and when the player clicks the onePlayerButton button, the game element is created and added to the frameLayout, brought to the fore, and the user starts playing the game.

  gv = new GameView(this, 1); fl.addView(fv, INDEX_GAMEVIEW_VIEW); fl.bringChildToFront(gv); fl.invalidate(); 

Then, when in the game, when the user clicks the pause icon in my gameView, the onTouchEvent () method catches it, and I do it. (I just made my pauseMenuView public so that my gameplay could see it) ... It looks like my program goes directly to the mThread.pause () line and does nothing with the first two lines ... I tried setting the game screen here it’s invisible, and when I do this, the screen is completely black, but I can click where the pause buttons will be, if the pause menu was visible, and they are really detected by my onClick () activity! What's going on here?

  ((TestGame)getContext()).fl.bringChildToFront(((TestGame)getContext()).pauseMenuView); ((TestGame)getContext()).pauseMenuView.bringToFront(); mThread.pause(); 
+4
source share

Source: https://habr.com/ru/post/1389341/


All Articles