Android tutorial (11)-usage of Five layout objects

Source: Internet
Author: User

In the tutorial in this chapter, we will learn how to use layout objects, because we have mentioned a lot about the use of controls, and controls must also be used.

So what is the layout? Android provides us with five la S. They are:

FrameLayout (frame type), LinearLayout (linear type), AbsoluteLayout (absolute type), RelativeLayout (relative type), and TableLayout (Table type ).

Let's take a closer look at their differences.

FrameLayout (frame type ):

FrameLayout is a simple layout. controls placed in it will be attached to the upper left corner. If we place multiple controls, they will overlap.

For example:

 

You must also note that you cannot change the position of the control at will!

 

 


LinearLayout (linear ):

The LinearLayout layout is often used in views such as "options", because the controls we put in will be separated by one row, in addition, only one widget can be placed in each row (except components that can also be placed in controls such as RadioGroup ).

For example:

 

It is worth noting that there are two linear la S: Vertical and Horizontal ).

 

 

 

AbsoluteLayout (absolute ):

The AbsoluteLayout layout refers to a view in which controls are located by coordinates (X, Y. The biggest advantage of this method is that you can freely move the widget's location, and the controls can overlap. However, the worst reason for this type of layout is that it is not recommended because it is not compatible with screens of various resolutions. In the screen of different resolutions, it may be all messy.

See the results:

 

If there is no targeted development, we do not recommend this layout method.

 

 


RelativeLayout (relative ):

RelativeLayout is the most flexible layout method, which is located by associating the relative positions of each control. The associated control must be defined. The associated control is also called the parent element.

Look at the results:

 

The parent element is pointed to. If we move the parent element, its child element will also be moved.

 

 

TableLayout (Table type ):

TableLayout layout should be an acceptable layout method. We can place TableRow in TableLayout. In this way, it can be used like a table.

 

 

Recently, because the company wants to build a mobile website, there are many things and there is no time to write a blog. It's rare to have a free time today. I 'd like to write a tutorial, or else I will become lazy.

 

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.