Android Mastery: View with viewgroup,linearlayout linear layout, Relativelayout relative layout, ListView list Component

Source: Internet
Author: User

Description of the UI

For an Android application, all user interface elements are built by View and ViewGroup objects. Viewis 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!

AndroidProvides 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 ViewIt 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 AndroidSeveral common layouts are available in:
    1. LinearLayoutLinear layout
    2. RelativeLayoutRelative layout
    3. FrameLayoutFrame layout
    4. AbsoluteLayoutAbsolute layout
    5. TableLayoutTable layout
    6. GridLayoutGrid 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:
    1. id:Add a resource to the componentid
    2. orientation:There are two ways to arrange in a layout:
      horizontalLevel
      verticalVertical
    3. layout_width:The width of the layout, represented by the wrap_content actual width of the component, match_parent representing the fill parent container
    4. layout_height:The length of the layout, represented by the wrap_content actual length of the component, to match_parent populate the parent container
    5. gravity:Controls the alignment of the child elements contained by the component
    6. layout_gravity:Controls how the component is aligned in the parent container
    7. background:Add a background picture to the component

LinearLayoutis 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>
RelativeLayoutRelative layout

RelativeLayoutis 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.

    1. layout_alignParentTop:For true , the upper boundary of the view is aligned with the top border of the parent
    2. layout_centerVertical:To true , place the subclass in the center of the parent class
    3. layout_below:Place the view below the resource ID
    4. 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>
GridViewGrid layout

GridViewis actually a grid-like view component, which is a ViewGroup two-dimensional view. The layout can be populated with an adapter.

ListView List Component

ListViewis 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

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.