Android development tutorial-layout (linear layout) (relative layout)

Source: Internet
Author: User

Hi everyone

It has been a long time since the last blog post was published. At the end of the year, the project was very busy. First, I couldn't take the time to update it. Second, it may be a bit lazy. Whatever the reason, sorry, we will continue to update it later. Thank you for your support!

As usual, relax: A young man smoked smoke at the door of an office building. A woman passed by and said to him, "Do you know this thing will harm your health? I mean, have you noticed the warning on the cigarette holder )?"

The young man said, "It's okay, I'mProgramMember ".

The woman said, "What is this ?"

The programmer said, "We never care about warning, but about error"

Today, we mainly talk about the layout in Android. Some people will say that a search on the network isArticleIt's boring. Indeed, after all, so many people are writing and posting blog posts, but it seems that there are not many articles that will explain these layout knowledge points using an example. This blog post mainly explains some basic knowledge points, in the next article, we will use an example to summarize the layout knowledge. below is the target effect, which will be discussed in the next blog to facilitate future reading. Skip this step!

Android has five major la s:

Linear Layout-linear Layout

Relative Layout-relative Layout

Table Layout-table layout

Relative Layout-absolutelayout

Frame Layout-framelayout

I often use linear and relative la s during development. Here I will mainly explain these two la S.

Linear layout is mainly divided into vertical linear layout and horizontal linear layout.

Android: Orientation = "vertical" and Android: Orientation = "horizontal" have the following effects:

 

 

•If the screen width or height is insufficient, deformation and incomplete display will occur. How can this problem be avoided?

• Android: layout_weight = "1"

• This attribute is important: the default value of each control is 0, which means that the control divides space based on its own width and height. If there are too many controls, when the screen is exceeded, it will be blocked.

• If this attribute is defined for each control and the value is 1, the free space of the parent element of the control is divided.

• For example, if there are five controls with each weight = 1, it means that the space of the parent element will be divided into five parts, and each control will occupy 1/5. The higher the weight value, the larger the proportion it occupies.

Generally, the UI is nested to implement complex la s, such as horizontal or relative la s of vertical linear sets, you need to do more.

Relative layout:

 

• Concept

• Allows child elements to specify their positions relative to other elements or parent elements (by ID ).

• If the layout file contains multiple layers of nested linearlayout, you can consider using the relative layout.

• Required attributes

• Android: layout_margintop = "25dip" // distance from the top

Android: gravity = "Left" // text position in the control

Android: layout_marginleft = "15dip // left margin

// Relative to the given ID Control

Android: layout_above: place the control at the bottom of the control on the control with the given ID (place the control on the control );

Android: layout_below: place the top of the control under the control with a given ID (place the control below the control );

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: Align the baseline of the control with the baseline of the given ID;

Android: layout_aligntop: Align the top edge of the control with the top edge of the given ID;

Android: layout_alignbottom: Align the bottom edge of the control with the bottom edge of the given ID;

Android: layout_alignleft: Align the left edge of the control with the left edge of the given ID;

Android: layout_alignright: Align the right edge of the control with the right edge of the given ID;

// Relative to the parent component

Android: layout_alignparenttop if it is true, align the top of the control with the top of its parent control;

Android: layout_alignparentbottom: If this parameter is set to true, the bottom of the control is aligned with the bottom of its parent control;

Android: layout_alignparentleft: if it is true, align the left of the control with the left of its parent control;

Android: layout_alignparentright: if it is set to true, align the right of the control with the right of its parent control;

• // Center
Android: layout_centerhorizontal if true, place the control horizontally in the center;
Android: layout_centervertical if true, place the control vertically in the center;
Android: layout_centerinparent if true, place the control in the center of the parent control;
// Specify the moving Pixel
Android: layout_margintop offset value;
Android: layout_marginbottom offset value;
Android: layout_marginleft value of the left offset;
Android: value of the right offset of layout_marginright;

The following is a simple logon box

Well, I have hardly used the remaining three la s during development. I personally feel that these two la s can implement complex pages. I have summarized the commonly used layout of Android-attributes help documentation and this section'sSource codeThey are all uploaded to the website of tianda. You can download them. Address http://www.tsdapp.com/android.html

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.