Android 什么是根视图?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12166905/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 09:57:15  来源:igfitidea点击:

What is a rootView?

androidhierarchy

提问by Se?fane Idouchach

Hello I'm new in Android and I've opened a project with the default template Master detail flowbut I don't know what is a rootView. I've search on developer.android.com but I don't really understood it ...

您好,我是 Android 新手,我使用默认模板Master detail flow打开了一个项目,但我不知道什么是rootView。我在 developer.android.com 上搜索过,但我真的不明白......

So if someone can explain me clearly what's this thing doing it would help me a lot.

因此,如果有人可以清楚地向我解释这件事是做什么的,那将对我有很大帮助。

Thanks !

谢谢 !

Edit : there is the code !

编辑:有代码!

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (getArguments().containsKey(ARG_ITEM_ID)) {
        mItem = DummyContent.ITEM_MAP.get(getArguments().getString(ARG_ITEM_ID));
    }
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_item_detail, container, false);
    if (mItem != null) {
        mLinearLayout = (LinearLayout)findViewById(R.id.layout); 
    }
    return rootView;
}

回答by Swayam

RootView is the View in which all the other views are placed. It is like the root node in a tree structure which is the parent to all the children.

RootView 是放置所有其他视图的视图。它就像树结构中的根节点,它是所有子节点的父节点。

For example, you have multiple Buttons in your layout which are placed inside a LinearLayout. Then LinearLayout is called the RootView as it would have the highest position in the structure and everything would have to be placed inside it.

例如,您的布局中有多个 Button,它们放置在一个 LinearLayout 中。然后 LinearLayout 被称为 RootView,因为它在结构中的位置最高,所有东西都必须放在里面。

Hope this clears your doubt.

希望这可以消除您的疑虑。

回答by Georg

This is a View, usually a ViewGroup that hosts all other views.

这是一个视图,通常是一个承载所有其他视图的视图组。

Thisis a nice starting point for how layouts work on Android which has an example in which a LinearLayoutserves as a root element.

是布局如何在 Android 上工作的一个很好的起点,其中有一个LinearLayout作为根元素的示例。

回答by Marcin Orlowski

Elements displayed are organized in tree hierarchy. For example if you put Button in Linear Layout container, then LinearLayout is parent for said Button. The top-most parent which got nothing "above" is "root". Same applies for i.e. folders and files - you get parent folder and there's also root folder - at the very top of the hierarchy

显示的元素按树层次结构组织。例如,如果您将 Button 放在 Linear Layout 容器中,则 LinearLayout 是所述 Button 的父级。没有任何“上面”内容的最顶层父对象是“根”。这同样适用于 ie 文件夹和文件——你得到父文件夹,还有根文件夹——在层次结构的最顶端