(5) Android layout control

Source: Internet
Author: User

First, LinearLayout (linear layout)

One of the most commonly used layouts, the characteristic of a linear layout is that each control adds a row below the previous control by default.

<LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Xmlns:tools= "Http://schemas.android.com/tools"Android:id= "@+id/linearlayout1"<!--layout's width attributes are: "Fill_parent", "Wrap_content", "match_parent"--><!--Fill_parent and Match_parent will enforce the view to the parent element size -<!--Wrap_content will fully display the text and images inside it -android:layout_width= "match_parent" android:layout_height= "Match_parent "<!--vertical Vertical, horizontal level -android:orientation= "Vertical"<!--How child elements are aligned in parent elements -android:gravity= "Bottom|right" >

Second, relativelayout (relative layout)

One of the most commonly used layouts, the relative layout feature is that the added space defaults to one overlay in the upper-left corner. The newly added control must specify the relative position of the other control in the property.

Third, tablelayout (table layout)

Features: A <TableRow> line with one more control column

Iv. framelayout (Frame layout)

Features: Overrides between controls. Application scenarios such as the button that appears in the middle of the screen when the video player pauses.

V. GridLayout (Grid layout)

Android4.0 introduced later. Easier to use than table layouts

1) You can set the arrangement of the components in the layout yourself
2) You can customize how many rows the grid layout has, how many columns
3) You can directly set the component to a column in a row
4) You can set the component to span several rows or columns

Typical cases, such as calculators

Vi. absolutelayout (Absolute layout)

Features: Can be dragged to the screen like WinForm, what you see is what you gain. However, when the resolution changes, the size and spacing of the controls change.

TextView

Drag the control into the phone, right-click Go to XML and see the following code

    <TextView        android:text= "TextView"        android:layout_width= "wrap_content"        android: layout_height= "Wrap_content"        android:layout_margintop= "14DP"        android:id= "@+id/textview2 " android:layout_below= "@+id/textview" android:layout_alignparentstart= "true"/>    

Android:id    Control uniquely identifies
Android:text  Display of text information
Android:layout_width Control width
Android:layout_height Control Height
Width and height There are three ways to assign values:
1. Fixed values such as 100DP can be set
2. Can also dynamically change "Wrap_content"
3. The width and height match_parent fill_parent (old version) can be adapted to the parent layout





DPI = pixel density----The number of dots you can print per inch-- inches is a line
160 dots on a 1-inch-long line, such as DPI, dpi160 is a standard screen


px= pixels |
DP (DIP) = device Independent pixel

1dp=1px at DPI 320 under the premise of the standard DPI 1dp=2px
Summarize
The higher The pixel density of the screen, the less it looks
Same DP with different pixel densities, looks as long
Reference




Android:lines= "5" shows 5 rows



(5) Android layout control

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.