Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What screen elements are there in Android

2025-01-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains "what screen elements are in Android". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let Xiaobian take you to learn "What screen elements are there in Android"!

android.app.Activity

For an Android app, android.app.Activity instances are the most basic functional unit. An Activity instance can do a lot of things, but it can't be displayed on the screen itself, but with the help of Viewgroups and Views, which 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 next layer of View objects and ViewGroup objects. ViewGroup is the base class for layout managers and view containers.

ViewGroup also defines a nested class ViewGroup.LayoutParams. This class defines a display object's location, size, etc. properties. View tells the parent how they will be placed by these property values in LayoutParams.

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

FrameLayout: The simplest layout object. It only shows one display object. All display objects in Android screen elements will be pinned to the upper left corner of the screen, and no position can be specified. However, multiple display objects are allowed, but the latter will be displayed directly on top of the former, partially or completely obscuring the former (unless the latter is transparent).

2. LinearLayout: Arrange and display the display objects in a single direction. If it is displayed vertically, there will be only one column in the Layout Manager; if it is displayed horizontally, there will be only one row in the Layout Manager. At the same time, it can also set the display scale for individual display objects.

TableLayout: Layout display objects in a table with arbitrary rows and columns, each display object is assigned to its own cell, but the border line of the cell is invisible.

4. AbsoluteLayout: Allow the specific position of the display object to be specified in the form of coordinates. The coordinates of the upper left corner are (0, 0). The coordinates increase downward and to the right. Because the position of the display object is fixed in this layout manager, the final display effect may not be consistent on different devices.

RelativeLayout: Allows layout by specifying the relative position of display objects relative to other display objects or parent objects. For example, one button can be placed to the right of another button, or it can be placed in the center of the Layout Manager.

In Android, there are many layout managers, which are not listed here. Developers can choose the appropriate layout manager according to actual needs.

android.view.View

View is the base class for all view classes, and a view usually occupies a rectangular area on an Android screen element and is responsible for drawing and event handling. View is the base class for all form parts and serves them, in this case UI controls such as a button or text box. Android already provides us with a range of standard UI controls for direct use, but we can also implement our custom UI controls by inheriting from the View class or subclasses of View.

To customize our own UI controls, we need to overload some of the methods in the View class. The following table lists the methods provided by View for overloading. These methods do not have to be overloaded, but at least the onDraw(android.graphics.Canvas) method should be implemented.

When you add a visible view to an activty and run the activty,android usually automatically triggers view-related events in the following order

onAttachedToWindow

onMeasure

onSizeChanged

onLayout

onDraw

For a screen in an Android app, Android screen elements are described hierarchically. To bind a hierarchical tree of screen elements to display on a screen, the Activity calls its setContentView() method and passes in a reference to the root node of the hierarchical tree. When an Activity is activated and gets focus, the system notifies the activity and asks the root node to compute and draw the tree, and the root node asks its children to draw themselves.

The ViewGroup node on each tree in an Android screen element is responsible for drawing its children. ViewGroup calculates its available space, lays out all child display objects, and finally calls the Draw() method of all child display objects to draw the display object. Individual child display objects can request their size and position in the layout from the parent object, but it is the parent object that ultimately determines the size and position of individual child display objects.

At this point, I believe that everyone has a deeper understanding of "what screen elements are in Android", so let's actually operate it! Here is the website, more related content can enter the relevant channels for inquiry, pay attention to us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report