What is a rootView?

戏子无情 提交于 2019-11-27 06:25:52

问题


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

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;
}

回答1:


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.

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.

Hope this clears your doubt.




回答2:


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

This is a nice starting point for how layouts work on Android which has an example in which a LinearLayout serves as a root element.




回答3:


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



来源:https://stackoverflow.com/questions/12166905/what-is-a-rootview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!