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

前端 未结 1 584
灰色年华
灰色年华 2020-12-14 11:22

I have a question regarding Android Activitys:

An Activity has the Method addContentView(View) while a ViewGroup has a (similar?) addView(View)

相关标签:
1条回答
  • 2020-12-14 11:54

    The base layout of every activity is a FrameLayout. This means the layout you usually set via setContentView() is a child of this layout. addContentView() adds just another child, therefore it behaves like a FrameLayout (which means it adds new UI elements above existing ones).

    You can check this by using a tool called hierachyviewer from your 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 a LinearLayout with a Button (my layout here). This is reflected in the bottom row here, the other elements above are the title/statusbar.

    enter image description here

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

    0 讨论(0)
提交回复
热议问题