Android detailed layout analysis-from the root layout to the specific layout

Source: Internet
Author: User

Android detailed layout analysis-from the root layout to the specific layout

One, analyze what the root layout of the Android program is, where we write the XML file to deploy to, Setcontentview (layout) is going on.

The tools in the Android SDK provide a tool for analyzing the hierarchy of programs: Hierarchyviewer.bat. In this tool, you can see the actual detailed layout of the program. Next, let's analyze, with the newly created project.

Second, open the Hierarchyviewer.bat tool and run a newly created project.

Second, what is the root layout of Android, or what is the root screen?

1. When you click on the root layout, a red area is displayed in the lower right corner, corresponding to the corresponding layout. You can see that when you click Phonewindow&decorview (Decorview is an inner class in the Phonewindow Class), the lower-right corner shows the full screen: the status bar (StatusBar), the Navigation Bar (toolbar), the Content bar ( Content). To know, this phonewindow&decorview is the root layout we're looking for.

Next, let's look at what it contains. Look, as you can see, when you click Actionbaroverlayout, the red area in the lower right corner contains the navigation bar and the content bar. The status bar is not included.

R.layout.activity_main layout is relationlayout layout, I put a textview and a button in it, in the picture can be clearly seen. The toolbar contains a TextView used to display the appname, and a Actionmenuview shows the hidden menu. This gives you a clear understanding of how our layout was arranged.

Here we can see that our Activity_main.xml file, the Setcontentview method, puts the XML file in the layout of an ID called content.

Three, we are in the mainactivity to test a bit.

Using the GetWindow method to get the Phonewindow class, Getdecorview get concrete Decorview class.

From Decorview can be assigned to view, Decorview is a visual component that is the root layout of the Activity window.

Print it with log to see if it is. You can see the tag in the log box. And Decorview's super class unexpectedly is framlayout is not very surprised.

This part of the knowledge is not much explained, but it is critical to understanding the overall layout. Come on!

Android detailed layout analysis-from the root layout to the specific layout

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.