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.