For my game, I am thinking of drawing UI elements (TextView for displaying time elapsed, Buttons for pausing/restarting game) on top of my GLSurfaceView
using RelativeLayout...
Till now, I was drawing all the UI elements myself directly to surfaceView but considering the wide options available from Android UI (like changing typeface of font and color), I have decided to use it.
Questions:
- Is it good practice to draw UI elements on top of
GLSurfaceView
or is it better to draw all the UI stuff myself directly toGLSurfaceView
? - I will be updating the content of the UI elements (Say
TextView
) regularly (for each 16 ms) by usingrunOnUiThread()
method... Is this bad? - Will my game be susceptible for Force Closes?
Here is the test java code which i am using to set up the RelativeLayout... glView
is the GLSurfaceView
instance.
rl = new RelativeLayout(this);
rl.addView(glView);
tv = new TextView(this);
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
lp.addRule(RelativeLayout.ALIGN_TOP);
tv.setLayoutParams(lp);
tv.setText("FPS: 0");
tv.setBackgroundColor(0x4060ff70);
rl.addView(tv);
setContentView(rl);