Search code examples
androidandroid-layoutandroid-viewglsurfaceview

How to add elements directly to FrameLayout at android:id/content?


I've been having some issues with understandng the view hierarchy of my app/device (as I'm having some problems with my application's splashscreen).

Basically, my app is an openGL ES 2.0 game and has the following elements:

  • Splashscreen's view (this is a standard Android View)
  • Main application's view (this is a GLSurfaceView)
  • Resources are loaded in the background (in an AsyncTask)

All I'm doing is this:

Creating my layout

 layout = new RelativeLayout(this);
 layout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));

Addding my GLSurfaceView and Splashscreen

 layout.addView(myGLView);
 layout.addView(splashscreen);  //loads resources on an AsyncTask

Removing the Splashscreen

When everything is loaded and ready, I simply remove the Splashscreen to reveal the GLSurfaceView underneath:

 layout.removeView(splashscreen);

When inspecting the view heirarchy of my app I see the following:

- My App's views

enter image description here

- Another Apps' Views

enter image description here

As you can see from the above graphics, my app has it's RelativeLayout which is the layout I'm creating in code (see above). This then gets added to the FrameLayout which has the resource ID of android:id/content.

I've downloaded 3 apps from the Play Store and inspected their layouts and they all have their views listed directly below this FrameLayout.

My question is what exactly is this FrameLayout and how can I get access to it and add my views (Main app, Banner ads, splashscreen), directly to it?

I have had a look around and none of the things I've read have really answered my question.


Solution

  • It's an activity's root view and can be fetched like this:

    FrameLayout frame = (FrameLayout) findViewById(android.R.id.content);