Most Android UI components are placed in the Android.widget,android.view package and its sub-packages, so the UI components inherit the view class, and the view represents a blank rectangular area.
Android all UI components are built on the view and viewgroup basis; The view class is the base class for all UI components, and ViewGroup is an abstract class that usually uses its subclasses as a container;
View class
The view class is the base class for all visual controls, and mainly provides methods for control and event handling, such as Textview,button,checkbox.
View class Common Properties and corresponding method description:
Android:background
Setbackgroundresource (int)
Set background
Android:clickable
Setclickable (Boolean)
Sets whether view responds to click events
Android:visibility
setvisibiltiy (int)
Control the visibility of a view
Android:focusable
Setfocusable (Boolean)
Controls whether the view can get focus
Android:id
SetId (int)
To set the identifier for the view, you can get the ID by using the Findviewbyid method
Android:longclickable
Setlongclickable (Boolean)
Sets whether the view responds to long click events
Android:soundeffecteabled
Setsoundeffectsenable (Boolean)
Sets whether the view triggers the click and other events to play sound effects
Android:saveenable
Setsaveenabled (Boolean)
Whether the view freezes when the state is saved
Android:nextfocusdown
Setnextfocusdownid (int)
Defines the view that gets the focus down
Android:nextfocusleft
Android:nextfocusright
Android:nextfocusup
View that defines the focus for different operational directions
Any subclass that inherits view has properties and methods as above;
The ViewGroup class is a subclass of the view class, but can act as a container for other controls, and the ViewGroup child controls can be either normal view or viewgroup;
About the relationship between view and ViewGroup
View is a base class, ViewGroup is a subclass of view;
View represents a block of space that can be drawn by a user interface component;
Each view occupies a rectangular area on the screen, where the view is responsible for image rendering and event handling;
The view class is the parent of the Gizmo widgets and ViewGroup; ViewGroup is the base class of layout;
Linear layout
Provides a model for horizontal or vertical control of controls;
Android:orientation
setorientation (int) Sets the orientation of the linear layout;
Android:gravity
setgrabity (int) Sets the layout of elements within a linear layout;
Table layout
The Tablelayout class manages controls in the form of rows and classes, each of which behaves as a TableRow object, or a view object that spans all classes of that row when it is a view object;
In a table layout, the width of a column is specified by the widest cell in the column, and the width of the table is specified by the parent container;
In Tablelayout, you can set the following 3 properties for a column;
shrinkable If a column is marked as shrinkable, the width of the column can be shrunk so that the table adapts to the size of its parent container;
stretchable if a column is stretchable by the flag bit, the width of the column can be stretched to fill the free space in the table.
Collapsed, the column will be hidden;
Tablelyout inherits the LinearLayout class, and the properties and methods that are unique to the Tablelyout class are as follows:
Setcolumncollapsed (Int,boolean)
Column number starting with 0, setting the column number specified as collapsed
Similarly, shrinkable,stretchable can be set;
Relativelayout
In relative layout, the position of the child control is relative to the sibling control or the parent container;
Property name |
Property Description |
Android:layout_centerhorizontal |
The current control is in the horizontal middle position of the parent control |
Android:layout_centervertical |
The current control is in the vertical middle position of the parent control |
Android:layout_centerinparent |
The current control is in the central location of the parent control |
Android:layout_alignparentbottom |
Aligns the bottom of the current control with the bottom of the parent control |
Android:layout_alignparentleft |
Aligns the left side of the current control with the left side of the parent control |
Android:layout_alignparentright |
Aligns the right side of the current control to the right side of the parent control |
Android:layout_alignparenttop |
Aligns the top of the current control with the top of the parent control |
Android:layout_alignwithparentifmissing |
Referencing a parent control when the reference control does not exist or is not visible |
Next, look at the property values for the other control IDs, as shown in table 3-6.
Table 3-6 Properties and descriptions for values in relative layouts for other control IDs
Property name |
Property Description |
Android:layout_torightof |
Causes the current control to be positioned to the right of the given ID control |
Android:layout_toleftof |
Causes the current control to be positioned to the left of the given ID control |
Android:layout_above |
Causes the current control to be positioned above the given ID control |
Android:layout_below |
Causes the current control to be located below the given ID control |
Android:layout_aligntop |
Aligns the top bounds of the current control with the top boundary of the given ID control |
Android:layout_alignbottom |
Aligns the bottom boundary of the current control with the bottom boundary of the given ID control |
Android:layout_alignleft |
Aligns the left bounds of the current control with the left edge of the given ID control |
Android:layout_alignright |
Aligns the right boundary of the current control with the right border of the given ID control |
Finally, the attributes and descriptions of the attribute values in pixels are described, as shown in table 3-7.
Table 3-7 Properties and descriptions of pixels in relative layout
Property name |
Property Description |
Android:layout_marginleft |
Leave white on the left side of the current control |
Android:layout_marginright |
Left white on the right side of the current control |
Android:layout_margintop |
White left over the current control |
Android:layout_marginbottom |
Leave white below the current control |
Framelayout class
Frame layout
Framelayout frame layout Creates an area on the screen where multiple child controls can be added, but all child controls are aligned to the upper-left corner of the screen, and the size of the frame layout is determined by the largest child control in the control, if the child controls are the same size, Only the topmost child controls can be seen at the same time;
The properties and methods that framelayout inherit from Viewgroup,framelayout are as follows:
Android:foreground
Setforeground (drawable)
Set the content to draw on all child controls
Android:foregroundgravity
setforegroundgraviety (int)
Sets the gravity property that paints content on all child controls
In Framelayout, the child controls are drawn through the stack, so the added child controls are drawn on top;
Absolutelayout class
The so-called absolute layout, refers to all the controls placed on the screen control position is specified by coordinates;
Android App Interface programming