Android Seventh Lesson--ui layout

Source: Internet
Author: User

The Android layout is divided into five types: linear layout, relative layout, table layout, frame layout, grid layout

Distance units in the layout: DP, PX, sp.

Layout inheritance diagram:

1) familiar with several common properties

<button android:id= "@+id/loginname"

Android:layout_width= "Wrap_content"

android:layout_height= "Wrap_content"

android:text= "@string/login"/>

android:id= "@+id/loginname"   Customize an ID for the component to find it in the program by mapping R files: r.id.loginname;
2) Android:layout_width and   Android:layout_height sets the width and height of the component, with only three values, namely:
Match_parent: Full parent container,
This property value is recommended for use in the new version Fill_parent: Full of the parent container, Span style= "font-family: Microsoft Jacob Black; font-size:14px; Background-color:rgb (255, 255, 255); " >
Wrap_content: Wrap text, set the size of the component according to the size of the text
3) android:text= "@string/login" to get the corresponding reference value from the constant

2)linearlayout linear layout

The linear layout , the LinearLayout layout, is a common layout in the Android screen and is a viewgroup that displays its sub-view elements in a linear direction , that is, vertical or horizontal. With regard to components, most of them are subclasses of view, so in many cases it is possible to call a component a view.

<linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"


Android:layout_width= "Match_parent"
android:layout_height= "Match_parent"
android:orientation= "Horizontal" >

-------------------

</LinearLayout>

1)android:orientation Determine whether the layout is vertical or horizontal

Horizontal: Horizontal

Vertical: Vertical

2) layout_weight (weight) Specifies the weight of the element in the LinearLayout (parent container), which is simply understood to mean that the weight of the component is divided by the sum of the weights of all the components that are the proportions (wide or high) in the parent component. Of course, there are a lot of circumstances, not generalize.

3) android:layout_gravity (alignment) specifies how the element is aligned in the LinearLayout (parent container), which is the alignment of the component itself.

4) Android:gravity: Refers to the alignment of the component's sub-components, compared to the above attribute, the above is the control itself in the parent container layout, and this is the control subassembly in its own container layout.

3) Relativelayout

Relative layout refers to a viewgroup that displays its child view (view) elements in a relative position , A view can specify a position relative to his sibling or Father's view position (for example, to the left or bottom of a given view) or to a specific area relative to the relativelayout (for example, bottom-aligned or right);

A powerful tool for designing the user interface relative to the layout, as he eliminates nested view groups. If the user finds that multiple nested linearlayout view groups are used, consider using a relativelayout view group.

The

Relative layout should be the most used layout in your application because it is the most flexible. In addition, we should keep a box model like CSS in mind when using relative layout, but Android, there seems to be no border property settings, but you can set the inner border and the outer border.

<relativelayout xmlns:android= "http://schemas.android.com/ Apk/res/android "&NBSP;
android:layout_width=" fill_parent "&NBSP;
android:layout_height=" Fill_parent ">

-------------

</LINEARLAYOUT>

1 "The first category: The   property value is True or false

3) Class III: Attribute values are specific pixel values, such as 30dip,40px


1) relative to the parent element
3) constraining its own subcomponents

First Class: Property value is True or False

    • Android:layout_centerhrizontal Horizontal Center

    • Android:layout_centervertical Vertical Center

    • Android:layout_centerinparent is completely centered relative to the parent element

    • Android:layout_alignparentbottom snaps to the bottom edge of the parent element

    • Android:layout_alignparentleft snaps to the left edge of the parent element

    • Android:layout_alignparentright snaps to the right edge of the parent element

    • Android:layout_alignparenttop snaps to the top edge of the parent element

    • android:layout_alignwithparentifmissing if the corresponding sibling element cannot be found, then the parent element is the reference.

Second class: The attribute value must be the reference name of the id "@id/id-name"

    • Android:layout_below at the bottom of an element

    • Android:layout_above at the top of an element

    • Android:layout_toleftof on the left side of an element

    • Android:layout_torightof on the right side of an element

    • Android:layout_aligntop aligns the top edge of this element with the top edge of an element

    • Android:layout_alignleft aligns the left edge of this element with the left edge of an element

    • Android:layout_alignbottom aligns the bottom edge of this element with the bottom edge of an element

    • Android:layout_alignright aligns the right edge of this element with the right edge of an element

Class III: Attribute values are specific pixel values, such as Xxdip,xxpx

    • Android:layout_margin distance from the outer edge of an element (including upper right lower left)

    • Android:layout_marginbottom distance from the bottom edge of an element

    • Android:layout_marginleft distance from the left edge of an element

    • Android:layout_marginright distance from the right edge of an element

    • Android:layout_margintop distance from the top edge of an element

    • The distance from the inner edge of the android:layout_padding (including upper right lower left)

    • Android:layout_paddingbottom the distance from the inner bottom edge

    • The distance from the left edge of the Android:layout_paddingleft

    • The distance from the right edge of the Android:layout_paddingright

    • The distance from the upper edge of the Android:layout_paddingtop

4) Tablelayout

The

table layout is represented by Tablelayout, and Tablelayout inherits LinearLayout. Tablelayout does not need to explicitly declare how many rows and columns are included, but rather to control the number of rows and columns of the table by adding TableRow and other components. Layout tablelayout only TableRow, each add a TableRow in Tablelayout to represent a new row, in fact, in tablelayout to write a component will default to occupy a row, but TableRow is actually a container, Each component in this container occupies one column. In a table layout, the width of the column is determined by the widest cell in the column, and the width of the entire table depends on the width of the parent container (the default is the full parent container).

<tablelayout xmlns:android= "Http://schemas.android.com/apk/res/android"     xmlns: tools= "Http://schemas.android.com/tools"     android:layout_width= "Match_parent"      android:layout_height= "Match_parent"     android:stretchcolumns= "2"      android:collapsecolumns= "0"     android:shrinkcolumns= "1"      >    <TableRow>        < Textview android:layout_width= "Wrap_content"               android:layout_height= "Wrap_content"               android:text= "@string/cell1"/>        < Textview android:layout_width= "Match_parent"               android:layout_height= "Wrap_content"               android:text= "@string/cell2"/>       <textview android:layout_ Width= "Match_parent"              android: layout_height= "Wrap_content"               android:text= "@string/cell3"/>    </tablerow>    <textview  android:layout_width= "Match_parent"               android:layout_height= "Wrap_content"               android:text= "@string/cell4"/></tablelayout>

1) First we can only control the column when we set the Tablelayout property, and the control of the column is calculated starting from 0.

2)Android:collapsecolumns: Hide the columns specified in the Tablelayout, and if more than one column needs to be hidden, separate the column numbers that need to be hidden by commas.

3) Android:stretchcolumns: Sets the specified column to be stretched to fill the remaining empty space in the parent container, and if more than one column needs to be set to stretch, separate the column numbers that need to be stretched with commas.

4) Android:shrinkcolumns: Sets the column that is specified to be shrunk. When the Lietaikuan (too much content) can be shrunk, the screen is not extruded. This property exactly consists of a pair with the Android:stretchcolumns property. when you need to set up multiple columns to shrink, separate the column numbers with commas.


Android Seventh Lesson--ui layout

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.