Five la s of the inventory page for Android software development (16)

Source: Internet
Author: User
Five la s of the inventory page for Android software development

Original by Yu Song MomoArticleIf you reprint it, please note: Reprinted to my independent domain name blogYusong Momo program Research Institute, Original address: http://www.xuanyusong.com/archives/133

1. Linear layout (linearlayout)

The linear layout can be divided into two forms: the first horizontal linear layout and the second vertical linear layout. All in all, they are arranged in linear form one by one, the disadvantage of pure linear layout is that it is inconvenient to modify the display position of the control. Therefore, the layout is usually set in the form of linear layout and relative layout nesting.

Using the horizontal and vertical directions of linear layout, we can clearly see that all controls are displayed in a linear arrangement, which is characteristic of linear layout.

Set the linear layout to the horizontal direction
Android: Orientation = "horizontal"
Set the linear layout to the vertical direction
Android: Orientation = "vertical"
Set the range of the proportional distribution control
Android: layout_weight = "1"
Set the display position of the control, which is centered horizontally.
Android: gravity = "center_horizontal"

In XML, I used linearlayout nesting to configure two linear la s, one horizontal display and one vertical display.

<? XML version = "1.0" encoding = "UTF-8"?> <Linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android" Android: layout_width = "fill_parent" Android: layout_height = "fill_parent" Android: Orientation = "vertical"> <linearlayout Android: layout_width = "fill_parent" Android: layout_height = "fill_parent" Android: Orientation = "horizontal" Android: gravity = "center_horizontal" Android: layout_weight = "2"> <imageviewandroid: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: src = "@ drawable/Jay"/> <textviewandroid: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: text = "Yu Song Momo" Android: Background = "# ff0000" Android: textcolor = "#000000" Android: textsize = "18dip"/> <edittextandroid: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: text = "Horizontal Direction"/> </linearlayout> <linearlayout Android: layout_width = "fill_parent" Android: layout_height = "fill_parent" Android: Orientation = "vertical" Android: layout_weight = "1"> <textviewandroid: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: text = "Yu Song Momo" Android: Background = "# ff0000" Android: textcolor = "#000000" Android: textsize = "18dip"/> <edittextandroid: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: text = "vertical"/> <buttonandroid: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: text = "Yu Song Momo"/> <imageviewandroid: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: src = "@ drawable/image"/> </linearlayout>


2. Relative layout (relativelayout)


Relative layout is the most powerful in Android layout. First, it can set the most attributes, and second, it can do the most. The screen resolutions of Android mobile phones are varied. Therefore, in order to consider screen adaptation, we recommend that you use relative la s in the development process so that it is correct to use them for adaptive screens..


Sets the right alignment from the parent Element
Android: layout_alignparentright = "true"
Set this control to the bottom of the control with ID re_edit_0
Android: layout_below = "@ ID/re_edit_0"
Set this control to the left of the re_image_0 control.
Android: layout_toleftof = "@ ID/re_iamge_0"
Set the alignment between the current control and the control whose ID is name
Android: layout_aligntop = "@ ID/name"
Set the offset pixel value
Android: layout_marginright = "30dip"

<? XML version = "1.0" encoding = "UTF-8"?> <Relativelayout xmlns: Android = "http://schemas.android.com/apk/res/android" Android: layout_width = "fill_parent" Android: layout_height = "fill_parent"> <edittextandroid: Id = "@ + ID/re_edit_0" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: text = "Yu Song Momo" Android: layout_alignparentright = "true"/> <imageviewandroid: id = "@ + ID/re_iamge_0" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: src = "@ drawable/Jay" Android: layout_below = "@ ID/re_edit_0" Android: layout_alignparentright = "true"/> <textviewandroid: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: background = "# ff0000" Android: text = "Learning" Android: textcolor = "#000000" Android: textsize = "18dip" Android: layout_toleftof = "@ ID/re_iamge_0"/> <edittextandroid: Id = "@ + ID/re_edit_1" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: TEXT = "Yu Song Momo" Android: layout_alignparentbottom = "true"/> <imageviewandroid: Id = "@ + ID/re_iamge_1" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: src = "@ drawable/image" Android: layout_above = "@ ID/re_edit_1"/> <textviewandroid: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: Background = "# ff0000" Android: text = "Working Hard" Android: textcolor = "#000000" Android: textsize = "18dip" Android: layout_torightof = "@ ID/re_iamge_1" Android: layout_above = "@ ID/re_edit_1"/> </relativelayout>

3. Frame layout (framelayout)

The principle is that any widget drawn in the widget can be overwritten by the widget drawn later. The last widget will cover the previous widget. The imageview first drawn on the interface is then rendered in textview and editview, so the latter overwrites the former.

<? XML version = "1.0" encoding = "UTF-8"?> <Layout: Android = "http://schemas.android.com/apk/res/android" Android: layout_width = "fill_parent" Android: layout_height = "fill_parent"> <imageviewandroid: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: src = "@ drawable/g"/> <textviewandroid: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: text = "Yu Song Momo" Android: background = "# ff0000" Android: textcolor = "#000000" Android: textsize = "18dip"/> <imageviewandroid: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: src = "@ drawable/image" Android: layout_gravity = "bottom"/> <edittextandroid: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: TEXT = "happy life every day" Android: layout_gravity = "bottom"/> </framelayout>

4. Absolute layout (absolutelayout)

With the absolute layout, you can set the x y coordinate points of any control on the screen. The control drawn after the same frame layout overwrites the previously drawn control, I do not recommend that you use absolute layout. That is to say, because Android mobile phones have a wide variety of resolutions, the absolute layout will not be displayed on other mobile phones.

Set the coordinate point of the widget.

 
Android: layout_x = "50dip" Android: layout_y = "30dip"

<? XML version = "1.0" encoding = "UTF-8"?> <Absolutelayout xmlns: Android = "http://schemas.android.com/apk/res/android" Android: layout_width = "fill_parent" Android: layout_height = "fill_parent"> <imageviewandroid: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: src = "@ drawable/F" Android: layout_x = "100dip" Android: layout_y = "50dip"/> <textviewandroid: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: text = "Current coordinate point X = 100dip y = 50 dip" Android: Background = "# ffffff" Android: textcolor = "# ff0000" Android: textsize = "18dip" Android: layout_x = "50dip" Android: layout_y = "30dip"/> <imageviewandroid: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: src = "@ drawable/H" Android: layout_x = "50dip" Android: layout_y = "300dip"/> <textviewandroid: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: text = "Current coordinate point X = 50dip y = 300 dip" Android: Background = "# ffffff" Android: textcolor = "# ff0000" Android: textsize = "18dip" Android: layout_x = "30dip" Android: layout_y = "280dip"/> </absolutelayout>

5. table layout (tablelayout)

In the table layout, you can set tablerow to set the content and position of each row in the table. You can set the display indent and alignment.

<? XML version = "1.0" encoding = "UTF-8"?> <Tablelayout xmlns: Android = "http://schemas.android.com/apk/res/android" Android: layout_width = "fill_parent" Android: layout_height = "fill_parent"> <imageviewandroid: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: src = "@ drawable/g" Android: layout_gravity = "center"/> <tablerow Android: layout_width = "wrap_content" Android: layout_height = "fill_parent" Android: padding = "10dip"> <textview Android: text = "name" Android: gravity = "Left"/> <textview Android: TEXT = "phone" Android: gravity = "right"/> </tablerow> <view Android: layout_height = "2dip" Android: background = "# ffffff"/> <tablerow Android: layout_width = "wrap_content" Android: layout_height = "fill_parent" Android: padding = "10dip"> <textview Android: TEXT = "Yu Song" Android: gravity = "Left"/> <textview Android: text = "15810463139" Android: gravity = "right"/> </tablerow> <tablerow Android: layout_width = "wrap_content" Android: layout_height = "fill_parent" Android: padding = "10dip"> <textview Android: text = "cute" Android: gravity = "Left"/> <textview Android: text = "15810463139" Android: gravity = "right"/> </tablerow> <tablerow Android: layout_width = "wrap_content" Android: layout_height = "fill_parent" Android: padding = "10dip"> <textview Android: text = "" Android: gravity = "Left"/> <textview Android: TEXT = "15810463139" Android: gravity = "right"/> </tablerow> <tablerow Android: layout_width = "wrap_content" Android: layout_height = "fill_parent" Android: padding = "10dip"> <textview Android: text = "name" Android: gravity = "Left"/> <textview Android: text = "gender" Android: gravity = "right"/> </tablerow> <view Android: layout_height = "2dip" Android: Background = "# ffffff"/> <tablerow Android: layout_width = "wrap_content" Android: layout_height = "fill_parent" Android: padding = "10dip"> <textview Android: text = "Yu Song Momo" Android: gravity = "Left"/> <textview Android: text = "male" Android: gravity = "right"/> </tablerow> <tablerow Android: layout_width = "wrap_content" Android: layout_height = "fill_parent" Android: padding = "10dip"> <textview Android: text = "cute" Android: gravity = "Left"/> <textview Android: TEXT = "" Android: gravity = "right"/> </tablerow> <tablerow Android: layout_width = "wrap_content" Android: layout_height = "fill_parent" Android: padding = "10dip"> <textview Android: text = "" Android: gravity = "Left"/> <textview Android: text = "male" Android: gravity = "right"/> </tablerow> </tablelayout>
The basic usage of the five la s of Android has been introduced. At last, I would like to emphasize that relative la s are recommended in development and learning, first of all, its method attributes are the most powerful. Secondly, it can basically achieve the effects of the other four la S. Of course, not all of the la s need to be used, therefore, the author suggests that you determine the actual situation in development. The preceding five la s can be nested to make better-looking and more beautiful la S.

In the end, if you still think that I am not writing enough details, it doesn't matter.Source codeYou are welcome to discuss and study Yu Song Momo, hoping to make progress together.

:Http://www.xuanyusong.com/archives/133

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.