Activity.addContentView (View) == ViewGroup.addContentView (View)?

I have a question about Android activity. Activity has an addContentView(View) method, while a ViewGroup has an addView(View) method (similar? addView(View) . Unfortunately, its undocumented "where" is located in "View from addContentView ". LinearLayout it look like LinearLayout , just adding a "View down"? Is this more like FrameLayout , which adds its "onTop" views? ViewGroup it depend on the ViewGroup set to setContentView ? If I dive into the sources, I see that addContentView will call the Window abstract Method addContentView . Unfortunately, I do not see which class implements this method. So what exactly is the behavior of addContentView exactly?

+11
android android-activity view window viewgroup
Apr 02 2018-12-12T00:
source share
1 answer

The basic layout of each action is FrameLayout . This means that the layout you usually set using setContentView() is a child of this layout. addContentView() only adds one more child, so it behaves like a FrameLayout (which means that it adds new user interface elements above the existing ones).

You can verify this using the hierachyviewer tool from the ANDROID_SDK\tools folder. Here are two screenshots:

enter image description here

This is the layout before calling addContentView() , my activity consists of the default FrameLayout holding the LinearLayout with a button (my layout is here). This is shown on the bottom line, and the rest of the items are the title / status bar.

enter image description here

After adding a TextView via addContentView() it looks like this. You can see that the base FrameLayout received a new child.

+36
Apr 02 '12 at 16:16
source share



All Articles