Concepts related to Android screen elements

Source: Internet
Author: User

There are a lot of important knowledge points in the Android mobile phone operating system that need to be detailed in the learning process to facilitate our future applications. For example, Android screen elements. Here we will introduce the layered structure of Android screen elements in detail.

  • Introduction to the correct implementation of Android read/write files
  • Android full screen
  • Basic concepts of Android floating point
  • Android Performance Comparison of advantages and disadvantages in actual development
  • In-depth analysis of Android code structure

Android. app. Activity

For an Android app, an android. app. Activity instance is the most basic function unit. An Activity instance can do a lot of things, but it cannot be displayed on the screen. Instead, Viewgroup and View are used. These two are the two most basic user interface expression units on the Android platform.

Android. view. ViewGroup

ViewGroup is a special View class that inherits from android. view. View. Its function is to load and manage the View objects and ViewGroup objects at the next layer. ViewGroup is the basic class of the layout manager layout) and view container.
ViewGroup also defines a nested class ViewGroup. LayoutParams. This class defines the location, size, and other attributes of the display object. view uses these attribute values in LayoutParams to tell the parent level how to place them.

Here, some main layout classes inherited from ViewGroup are as follows:

1. FrameLayout: the simplest layout object. It only displays one display object. All Display objects in the Android screen element are fixed in the upper left corner of the screen and cannot be specified. However, multiple explicit objects are allowed, but the last one will overwrite the previous one and block the previous one or all unless the last one is transparent ).

2. LinearLayout: arrange and display the display objects in a single direction. For example, if the display objects are vertically arranged, the layout manager only has one column. For example, the display objects are horizontally arranged, there will be only one row in the layout manager. It can also set the display ratio for individual display objects.

3. TableLayout: la s display objects in tables with any row or column. Each Display object is allocated to its respective cells, but its border line is invisible.

4. AbsoluteLayout: allows you to specify the specific position of the object to be displayed in the form of coordinates. The coordinates in the upper left corner are (0, 0), down and right, and the coordinates increase. Because the location of the display object is fixed, the layout manager may have different display effects on different devices.

5. RelativeLayout: Allows layout by specifying the relative position of the display object relative to other display objects or parent objects. For example, a button can be placed on the right of another button or in the center of the layout manager.
In Android, many layout managers are provided, which are not listed here. developers can select the appropriate layout manager based on their actual needs.

Android. view. View

View is the base class of all view classes. A view usually occupies a rectangular area on the Android screen element and is responsible for plotting and event processing. View is the base class of all form parts and serves form parts. The form part is a UI control, such as a button or text box. Android has provided us with a series of standard UI controls for our direct use. At the same time, we can also implement our custom UI controls by inheriting to the View class or View subclass.

To customize our own UI controls, you need to reload some methods in the View class. The following table lists the methods provided by the View for overloading. These methods do not have to be reloaded, but at least onDraw (android. graphics. canvas) method.

When you add a visible view to an activty and run this activty, android will automatically trigger view-related events in the following order.

  1. OnAttachedToWindow
  2. OnMeasure
  3. OnSizeChanged
  4. OnLayout
  5. OnDraw

For a screen in an Android Application, the Android screen elements are described in a hierarchical structure. To bind a screen element hierarchy tree to a screen for display, Activity will call its setContentView () method and pass in the root node reference of this hierarchy tree. When the Activity is activated and the focus is obtained, the system will notify the activity and request the root node to calculate and draw the tree. The root node will request its child nodes to draw their own.

The ViewGroup node on each tree in the Android screen element is used to draw its child nodes. ViewGroup calculates its effective space, layout all sub-display objects, and finally calls the Draw () method of all sub-display objects to Draw the display objects. Each child Display object can request the size and position of the parent object in the layout, but the parent object determines the size and position of each child Display object.

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.