Android Study Notes (3) UI Layout

Source: Internet
Author: User

1. Linear Layout-LinearLayout (top-down layout)
<LinearLayout>
</LinearLayout>
For example:
Java code
<LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android"
Android: orientation = "vertical"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
>
 

Where
Android: orientation = "vertical" means vertical
The linear layout of the direction. Here, the "vertical" can be changed to "horizontal", which means the linear layout of the horizontal direction.
Android: layout_width = "fill_parent" means that the width of this control is full of the screen or parent control. Here, "fill_parent" can be changed to "wrap_parant ", it means that the width exactly contains the content in LinearLayout.
 
Common Layout controls:
 
 

Android: id

Specify the corresponding ID for the control

Android: text

Specify the text displayed in the control. Note that strings in the strings. xml file should be used as much as possible here.

Android: gravity

Controls the position of a widget, such as center, right, bottom, and top.

Android: textSize

Specifies the font size in the control.

Android: background

Specifies the background color used by the control. The RGB naming method is used.

Android: layout_weight

The number of values indicates the number of values that the control occupies the entire screen. For example, there are two controls in the current Activity. The first control is android: layout_weight = "2 ", the second control is android: layout_weight = "3". The first control accounts for 3/5 of the screen.

Android: height

Height of the control

Android: padding *

Specify the padding of the control, that is, the content in the control, such as android: paddingLeft = "10dip", android: paddingRight = "10dip", and so on. You can also use android: padding = "10dip" to indicate that the four sides of the padding are 10.

Android: singleLine

If set to true, all contents of the control are displayed in the same row.

 

 
Ii. table layout-TableLayout
Overview:
TableLayout is mostly used for list display.
1. Place child elements in rows and columns.
2. Do not display the line of rows, columns, and cells.
3. Cells cannot span rows, similar to html.
 
Use Case:
Java code
<TableLayout xmlns: android = "http://schemas.android.com/apk/res/android"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
Android: stretchColumns = "1"> // This statement indicates that the second column of all rows in TableLayout is set to the stretch column. That is to say, if each row has three columns, the remaining space will be filled by the second column. If the value is 0, the first column is the stretch column. The purpose is to fill up the parent control.
 
<TableLayout>
<TableRow>
<TextView
Android: text = "@ string/row1_column1"
Android: background = "# aa0000" // Add the background color
Android: padding = "3dip"
 
/>
<TextView
Android: text = "@ string/row1_column1"
Android: padding = "3dip"
Android: gravity = "center_horizontal" // vertical center display
Android: background = "#00aa00"
/>
<TextView
Android: text = "@ string/row1_column2"
Android: gravity = "right" // right-side display
Android: background = "# tianaa"
Android: padding = "3dip"
 
/>
</TablieRow>
</TableLayout>
The code above indicates that the screen is divided into three columns. A TableRow is a row, and each TextView occupies a cell.

 
3. nested layout
That is, multiple la s are nested.
To implement the following layout: Multiple LinearLayout nesting
 


 

The Code is as follows:
Java code
<? Xml version = "1.0" encoding = "UTF-8"?>
<LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android"
Android: orientation = "vertical" // use vertical layout on the outermost layer
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
>
<LinearLayout
Android: orientation = "horizontal" // The first nested vertical layout
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
Android: layout_weight = "1" type = "codeph" text = "codeph"> // You must note that the nested LinearLayout has a weight of 1, that is, each of them occupies half of the screen.
</LinearLayout>

<LinearLayout
Android: orientation = "vertical" // second nested vertical layout
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
Android: layout_weight = "1">
</LinearLayout>
</LinearLayout>
Iv. Relative Layout-RelativeLayout
Concept:
Similar to CSS + DIV layout.
The position of a widget depends on its relationship with the surrounding controls.
 
Differences from other controls:
The relative layout is determined by the relationship between the dependency and the surrounding controls. For example, place control A under control B.
 
Related attributes:
Category 1:
Java code
Android: layout_above: Move the control's bottom to the control with the given ID
Android: layout_below: place the top of the control under the control with the given ID
Android: layout_toLeftOf align the right edge of the control with the left edge of the control with the given ID
Android: layout_toRightOf align the left edge of the control with the right edge of the control with the given ID

Android: layout_alignBaseline the baseline of the control is aligned with the baseline of the control with the given ID
Android: layout_alignBottom: Compares the bottom edge of the control with the bottom edge of the given ID control.
Android: layout_alignLeft: Align the left edge of the control with the given ID
Android: layout_alignRight: Align the right edge of the control with the right edge of the given ID Control
Android: layout_alignTop: aligntop


Android: layout_alignParentBottom if the value is true, the bottom of the control is aligned with the bottom of the parent control.
Android: layout_alignParentLeft if the value is true, the left side of the control is aligned with the left side of the parent control.
Android: layout_alignParentRight if the value is true, the right side of the control is aligned with the right side of the parent control.
Android: layout_alignParentTop if the value is true, the top of the control is aligned with the top of the parent control.

Android: layout_centerHorizontal
Android: layout_centerInParent if the value is true, the control is centered in the horizontal and vertical directions of the parent control.
Android: layout_centerVertical if the value is true, the control will be centered in the vertical direction

 
In general, Padding is an internal border, and Margin is an external border.
 
The corresponding property is
 
Android: layout_marginBottom = "25dip"
Android: layout_marginLeft = "10dip"
Android: layout_marginTop = "10dip"
Android: layout_marginRight = "10dip"
Android: paddingLeft = "1dip"
Android: paddingTop = "1dip"
Android: paddingRight = "1dip"
Android: paddingBottom = "1dip"
 
If both the left and right are the same settings, you can set them directly.
 
Android: layout_margin = "10dip"
Android: padding = "5dip"

 

This article is from "suuu"

 

Related Article

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.