Author: Han Ru

Company: Program Ka (Beijing) Technology Co., Ltd

Hongmeng Bus columnist

Applied Ability displays a user interface on the screen that displays all the content that can be viewed and interacted with by the user.

All user interface elements in the application are made up of Component and ComponentContainer objects. Component is an object drawn on the screen that the user can interact with. ComponentContainer is a container that holds other Components and ComponentContainer objects.

The Java UI framework provides some concrete subclasses of Component and ComponentContainer, that is, the various components that create the user interface (UI), including some commonly used components (such as: text, buttons, images, lists, etc.) and commonly used layouts (such as: Directionallayout and DependentLayout). The user interacts with the component and gets a response.

All UI operations should be set up on the main thread.

I. Components and Layout

The user interface elements are collectively called components, which are combined to form a layout according to a certain hierarchical structure. Components can neither display nor interact without being added to the layout, so a user interface contains at least one layout. In the UI framework, the specific layout class is usually named XXLayout, the entire user interface is a layout, part of the user interface can also be a layout. The layout holds Component and ComponentContainer objects.

Component and ComponentContainer

  • Component: Provides content display and is the base class for all components in the interface. Developers can set event handling callbacks to Component to create an interactive Component. The Java UI framework provides some common interface elements, also known as components, which inherit directly from Component or its subclasses, such as Text, Image, and so on.
  • ComponentContainer: Houses Component or ComponentContainer objects as containers and lays them out. Java UI frameworks provide containers for standard Layout functions that inherit from ComponentContainer and typically end with a “Layout”, such as Directionallayout, DependentLayout, and so on.

Figure 1 Component structure

Third, LayoutConfig

Each layout provides LayoutConfig for child components to set layout properties and parameters according to its own characteristics. Layout properties can be specified to restrict the display effect of child components in the layout. For example, “width” and “height” are the most basic layout properties that specify the size of the component.

Figure 2 LayoutConfig

Component tree

Layouts organize components and ComponentContainers in a tree-like hierarchy. Such a layout is called a Component Tree. The feature of a component tree is that there is only one root component, while other components have only one parent node, and the relationships between components are governed by the rules of the parent node.

More:

1, community: https://www.harmonybus.net/ HongMeng bus

2. Official Account: Harmonybus

3, technical exchange QQ group: 714518656

Lesson 4, video: https://www.chengxuka.com