Description of the UI
For an Android
application, all user interface elements are built by View
and ViewGroup
objects. View
is an object that draws on the screen to interact with the user. And for ViewGroup
that, it's a View
layout container for other and ViewGroup
objects!
Android
Provides us with a View
ViewGroup
collection of two subclasses that provide commonly used input controls (such as buttons, pictures and text fields, etc.) and a variety of layout patterns (such as thread layout, relative layout, absolute layout, frame layout, table layout, etc.).
User interface Layout
On your APP
software, each component displayed on the user interface is made up View
of hierarchies and ViewGroup
objects, for example, each ViewGroup
is an invisible container, each ViewGroup
view group is used to organize the container for the child view View
, and its child view View
It is possible to enter some controls or widgets in a block area UI
. If you have a hierarchy tree, you can design some layouts to suit your needs, but try to be as simple as possible because the simpler hierarchies are best for performance.
To declare a layout, you can instantiate the object and build it in your code, and the simplest method can also use the xml
file.
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TextView android:id="@+id/text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="TextView" /> <Button android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" /></LinearLayout>
In
Android
Several common layouts are available in:
LinearLayout
Linear layout
RelativeLayout
Relative layout
FrameLayout
Frame layout
AbsoluteLayout
Absolute layout
TableLayout
Table layout
GridLayout
Grid layout
Describe a few important
Linear layout:
Refers to child controls arranged horizontally or vertically .
Relative layout:
Refers to a child control arranged in a relative position between controls or on the position of a child control relative to the parent container.
Frame layout:
means that all child controls are placed in the upper- left corner and the following elements are directly above the preceding element.
Absolute layout:
A child control determines its position by absolutely locating the x, y position .
Table layout:
refers to placing child controls as rows and columns, each of which is a TableRow object or View object.
LinearLayout Linear Layout Common properties:
id:
Add a resource to the componentid
orientation:
There are two ways to arrange in a layout:
horizontal
Level
vertical
Vertical
layout_width:
The width of the layout, represented by the wrap_content
actual width of the component, match_parent
representing the fill parent container
layout_height:
The length of the layout, represented by the wrap_content
actual length of the component, to match_parent
populate the parent container
gravity:
Controls the alignment of the child elements contained by the component
layout_gravity:
Controls how the component is aligned in the parent container
background:
Add a background picture to the component
LinearLayout
is a view group that distributes all children vertically or horizontally in one direction, using android:orientation
attributes.
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="输入账号" /> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="输入密码" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="登录" /></LinearLayout>
RelativeLayout
Relative layout
RelativeLayout
is a relative layout of the view group that displays the relative position of the child view class, by default, all child view pairs are distributed in the upper-left corner.
layout_alignParentTop:
For true
, the upper boundary of the view is aligned with the top border of the parent
layout_centerVertical:
To true
, place the subclass in the center of the parent class
layout_below:
Place the view below the resource ID
layout_toRightOf:
Place the view to the right of the resource ID
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <EditText android:id="@+id/name" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="你的名字" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/name" android:layout_alignParentRight="true" android:text="正确" /></RelativeLayout>
GridView
Grid layout
GridView
is actually a grid-like view component, which is a ViewGroup
two-dimensional view. The layout can be populated with an adapter.
ListView List Component
ListView
is a scrollable view group for displaying lists, and list items can be added with adapters.
Conclusion
This article mainly explains? Android Mastery: View with viewgroup,linearlayout linear layout, Relativelayout relative layout, ListView list Component
Below I will continue to Java
,? Android
In-depth explanation of other knowledge, and interested to continue to focus on
A little gift to walk or like.
Android Mastery: View with viewgroup,linearlayout linear layout, Relativelayout relative layout, ListView list Component