View and ViewGroup class relationships
Android View and ViewGroup from the composition of the architecture, it seems that viewgroup on the view, the view needs to inherit ViewGroup, but in fact it is not. View is the base class, and ViewGroup is its subclass. This proves that the view represents a block of space that can be drawn for user interface components. Each view occupies a rectangular area on the screen. Within this area, this view object is responsible for drawing and event handling. View is the parent of small controls widgets and ViewGroup, and ViewGroup is the base class for layout.
From the two diagram above, it can be seen that, in fact, ViewGroup is the subclass of the view, therefore, the view behavior features ViewGroup also have, at the same time, because ViewGroup is the ancestor of layout, so have some other features, view does not have. You typically create a view, whether it is created through XML or through code. There are a few things you need to focus on for any of the view and sub-category widgets:
"1" Setting properties : such as length, width, coloring, and so on. The settings for these properties can often be implemented in code or in XML files. These properties can also be modified at run time by means of methods.
Id:android requires unique, but not absolute, id names for each UI element. At the same time, it is possible to have the same element name in different layout. Assigning an ID to a UI element has the advantage of being able to find it in the code.
Orientatiion: For ViewGroup's subclass layout, set Orienatation, which can be used to determine the location of subclasses.
Fillmodel: This occurs primarily by default, some elements do not fully fill the space of the parent area, and unless the child view is already set to specific and DPI, the message needs to tell the parent control how you choose to fill the space, such as fill-parent or wrap-content.
Gravity:gravity is different from orientation, gravaity is similar to left-aligned and right-aligned in Word documents. The default is top-left alignment.
Weight: This is a two-control allocation of the remaining space, need to set Layout-weight decide who is the ratio.
"2" Request focus: You can use the function to achieve focus conversion, different focus can achieve different background transformations and other functions. Focus on Android is divided into several situations, one is to get focus, the other is to not get the focus, the third is to get the focus, but the current is taking the touch state.
"3" Set event Listener: All of the view will broadcast its own information as it changes itself. The analogy clicks, the focus loses to obtain and so on. Usually an event arrives, and Android passes the event to the appropriate view, and then the view passes the event to the appropriate listeners. At this point, the view needs to get the focus and if you need to redraw the view, call invalidate (0 or reqeustlayout to redraw the entire interface).
The "4" setting is displayed and hidden, and you can set scrolling for its contents.
Relationship between View, Window, Activity, Dispay
These are the key elements that make up the Android system display. Let's start by understanding Dispay. Dispay represents the Hardware display screen information.
These functions can be used to understand the width, height and resolution of a screen, as well as the horizontal screen and other basic conditions, through these functions, we develop the application can easily get the current installation of my application's screen size, in order to adjust the application users to get a better user experience. Next we look at the relationship between the other three, I think we see the previous view of the introduction and the SDK in the basic interface of the UI is still very confusing to the Android graphics window, see the API also, there are WINDOWMANGAER interfaces and the window class, but in the documentation, Did not mention how to use these. But in fact this is going to see Android core, Android core underlying GDI is Skia, and Chrome is the same GDI, but the GUI is not the same. The Android implementation of this is the C/s mode. As shown
From that, we can sort out the approximate display process as follows:
"1" activitymanagerservice Create activity thread, activate an activity
The "2" system calls Instrumentation.newactivity to create an activity
After the "3" activity is created, attach into a newly created phonewindow. This activity gets a unique instance of the WindowManager service
The "4" activity was created using the Setcontentview settings with the user UI, which are added to the Phonewindow contentparent.
The "5" activity thread continues execution when it executes to theactivity.makevisible is to add the root view Decoview to Windowmanger, windowmanger the actual plenary to create a corresponding decoview for each viewroot
"6" Each viewroot has a surface, and each surface will call the underlying library to create a graph-drawn memory space. This bottom-level library is Surfaceflinger. Surfaceflinger is also responsible for displaying the graph of a view drawing to a piece (on the Z axis) to the user's screen.
"7" If the user draws directly on the canvas, it actually operates directly on surface. But for each view change, it is to be notified to Viewroot, and then Viewroot gets the canvas. If the drawing is complete, Surfaceflinger is notified to merge surface into a surface to the device screen.
From the above graphical output process analysis, we can know that the actual display of graphics is actually not related to the activity, completely determined by the WindowManager. WindowManager is a system service, so you can call this service directly to create the interface, and more definitely dialog, menu is also managed by WindowManager. In addition, we can also see that the bottom layer is surface to manage. Therefore, it is recommended that you use Surfaceview to create an interface for common development games.
Android Interface View and ViewGroup learning "reprint"