Android miscellaneous-Relationship between activity, window, and view

Source: Internet
Author: User

I. First, let's talk about view and viewgroup.

All the UI classes in the Android system are built on the view and viewgroup classes. The child classes of all views become "widgets", and the Child classes of all viewgroups become "layout ". The view and viewgroup adopt a combination design mode to make "part-whole" treat the same. As the top layer of the layout container class, viewgroup can have view and viewgroup in the layout container.

2. What are the meanings of layoutinflater and layoutinflater. Inflate?

Layoutinflater is a class used to instantiate an XML layout file as a view object.

Layoutinflater. infalte (R. layout. Test, null) is used to fill in a new view from the specified XML resource.

3. Relationships among activities, windows, and views

When we run the program, there is a setcontentview () method. The activity is not actually a display view (intuitively it is). In fact, the activity calls the setcontentview () method of phonewindow, then load the view and put the view on this window. The activity is actually initialized with the phonewindow structure. The activity is actually a control unit, that is, a visual human-machine interaction interface.

A metaphor:

Activity is a worker who controls the window. Window is a display screen used to display information. view is the information to be displayed on the display screen, these views are stacked together (via infalte () and addview () and placed on the window display. Layoutinfalter is a tool used to generate a view. The XML layout file is used to generate a view.

Let's talk about the specific execution process in the code.

Setcontentview (R. layout. Main) is actually the following content. (It is more intuitive to comment out the following code)

Getwindow (). setcontentview (layoutinflater. From (this). Inflate (R. layout. Main, null ))

After the program is run, the activity calls setcontentview () of phonewindow to generate a window, and setcontentview is the bottom view. Then, the layoutinflater. infalte () method is used to load the layout to generate a view object, and addview () method is used to add the object to the window (layer by layer)

Therefore, the activity is not a display view, but a view is a real display view.

Note: Only one phonewindow can be initialized when an activity is constructed. In addition, this phonewindow has a "viewroot". This "viewroot" is a live view viewgroup, is the initial view, and then the views are stacked to the viewroot one by one through the addview method. These stacked views are finally placed on the carrier of the window.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.