Android section II (view introduction and Android Layout manager), Dimension review

Source: Internet
Author: User

The layout manager specifies how the view is arranged. View is UI control, next lesson I will organize, here we first talk about layout, large layout in my opinion is equivalent to a room, let view display, that is, the item in the room of the rules.


First, the view of the introduction

View, generally have textview,edittext,button,radiobutton,checkbox,imageview,imagebutton.

ViewGroup, generally have linearlayout,relativelayout,framelayout,spinner,listview,gridview.

Each view has a corresponding label in the layout, such as TextView, whose label is <TextView>


The relationship between layouts and activity: layouts can only be loaded and displayed in activity or dialog, as in the OnCreate () method in Mainactivity: Setcontentview (r.layout. Layout name), which is the load layout.


How to access and modify the properties of the view control in activity: first to find in the layout, the corresponding control's ID, such as TextView's ID is TV, then define a global variable private TextView TextView; in OnCreate () Method: Textview=findviewbyid (r.id.tv), tv.setxxx () to set the related properties.


The commonly used properties are: Id,layout_width,layout_height,background.

The usual methods that correspond to attributes are: SetText (String), settextsize (float), settextcolor (int), Setsingleline (Boolean), Setlines (int), Setmaxlines (int), setautolinkmask (int).

where setautolinkmask ()

Textview.setautolinkmask (Linkify.web_urls)/////////////When text in text content contains hyperlink format, automatically convert to hyperlink style, click to automatically jump to the specified page
Textview.setautolinkmask (linkify.phone_numbers);//auto-turn phone number click on it to enter the system dial-up interface
Textview.setautolinkmask (linkify.email_addresses);//auto-forward email address click it to send mail (to set up your own email in advance)
Textview.setautolinkmask (linkify.map_addresses);//auto-turn street address Click on it to view the location (if Google Maps is already installed)
Textview.setautolinkmask (Linkify.all);//includes the above 4 cases


Second, layout manager

There are 5 types of layout managers, namely:

Linear layout: LinearLayout.

Relative layout: Relativelayout.

Table layout: Tablelayout.

Absolute layout: absolutelayout (deprecated).

Frame layout: Framelayout

1, LinearLayout

(1) The properties noted in the linear layout are: orientation= "horizontal|vertical", when more than one view does not have this attribute will be error.

(2) The second need to be noted is the use of weight:

The Width/height property of the control must be consistent;

width/height= "0DP" weight value, the larger the occupied space (positive proportion);

width/height= "match_parent" weight value, the larger the space occupied (inverse proportion);

The larger the weight value of width/height= "Wrap_content", the larger the space occupied (positive proportion);

Width/height is not "0DP", the system will give priority to the weight of small components, temporarily do not put code, please forgive me.

(3) Gravity is the control content and the alignment of the child control, the specific properties of the shortcut keys will come out, here is not introduced.

(4) Layout_gravity is the alignment of the control in the parent layout.


2, Relativelayout relative layout

This attribute is divided into two parts, one relative to the sibling control and one relative to the parent control.

(1) Relative sibling controls:

Drop Location:

Toleftof the left position of the specified sibling control

Torightof the right position of the specified sibling control

Below the bottom position of the specified sibling control

Above the upper position of the specified sibling control

Alignment:

AlignLeft left-aligned with the specified sibling control

AlignRight right-aligned with the specified sibling control

AlignTop aligns with the top of the specified sibling control

AlignBottom aligns to the bottom of the specified sibling control

Alignbaseline aligns with the specified sibling control content

(2) Relative parent control:

Position alignment:

Alignparentleft placed on the left side of the parent control (the default is this placement)

Alignparentright placed on the right side of the parent control

Alignparenttop placed at the top of the parent control

Alignparentbottom placed at the bottom of the parent control

Center alignment:

Centerinparent placement at the center of the parent control

Centerhorizontal the horizontal center position of the parent control

Centervertical the vertical center position of the parent control


3. Framelayout Frame Layout

Layout_gravity sets the location of the child control

foreground= the "#4f00" setting is drawn on top of all child controls drawable

Foregroundgravity sets the Gravity property of drawable that is drawn on top of all child controls

Measureallchildren calculating the size of all child controls


About the layout of this piece, basically commonly used is the linear layout and relative layout, we must grasp the two parts clearly. Welcome Reprint



This article is from the "Vivian Son" blog, please be sure to keep this source http://9550674.blog.51cto.com/9540674/1576841

Android section II (view introduction and Android Layout manager), Dimension review

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.