Activity.addContentView(查看)== ViewGroup.addContentView(查看)? [英] Activity.addContentView(View) == ViewGroup.addContentView(View)?

查看:620
本文介绍了Activity.addContentView(查看)== ViewGroup.addContentView(查看)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有关于Android的Activitys的问题。某一行为的方法 addContentView(查看)而ViewGroup中有一个(类似于?) addView(查看)方法。不幸的是它的无证,其中的从 addContentView 查看放置。难道喜欢一个的LinearLayout 只是增加了视图的底部?是不是更像是一个的FrameLayout ,这将增加其意见onTop?是否依赖于的ViewGroup 的setContentView 设置? 如果我潜入我看到的来源 addContentView 将调用窗口的抽象方法 addContentView 。不幸的是,我不能看到哪个类实现此方法。因此,whats Activitys的行为 addContentView 到底是什么?

I have a question regarding Android Activitys. An Activity has the Method addContentView(View) while a ViewGroup has a (similar?) addView(View) Method. Unfortunately its undocumented "where" the View from addContentView is placed. Is it like a LinearLayout just adding the View to the bottom? Is it more like a FrameLayout, which adds its Views "onTop" ? Does it depend on the ViewGroup set by setContentView? If I dive into the sources I see that addContentView will call Window's abstract Method addContentView. Unfortunately I cannot see the which class is implementing this Method. So whats the behaviour of Activitys addContentView exactly?

推荐答案

每一个活动的基本布局是一个的FrameLayout 。这意味着您通常是通过的setContentView设置布局()是这样布局的孩子。 addContentView()补充说只是一个孩子,因此,它的行为就像一个的FrameLayout (这意味着它增加了新的用户界面上述现有的那些元素)的。

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).

您可以通过使用一种称为工具<一检查这href="http://developer.android.com/guide/developing/debugging/debugging-ui.html"><$c$c>hierachyviewer从你的 ANDROID_SDK \工具文件夹。这里有两个屏幕:

You can check this by using a tool called hierachyviewer from your ANDROID_SDK\tools folder. Here are two screenshots:

这是,我的活动包括默认的FrameLayout的,抱着的LinearLayout一个按钮(我在这里的布局)之前调用布局 addContentView()。这反映在这里的底行中,上述的其他元件的标题/状态栏。

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.

通过添加一个TextView addContentView后()它看起来像这样。你可以看到,该基地的FrameLayout得到了一个新的孩子。

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

这篇关于Activity.addContentView(查看)== ViewGroup.addContentView(查看)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆