Share five common Android layouts

Now Android is very crazy, so online learning materials about Android have sprung up, and there are many basic things like these. I will record the difficulties encountered and how to solve the used things, so that I can review them for myself. In case of similar problems in the future, I can take a look directly. Second, it can give beginners a little help.

Android layout is an important part of application interface development. In Android, there are five layout methods: FrameLayout, LinearLayout, absolutelayout, relativelayout and tablelayout

1、 FrameLayout

This layout can be seen as a pile of things at the foot of the wall. There is a square rectangle at the top left corner of the wall. We put the first thing, and we want to put another one, which will be placed on the original position. In this way, it will cover the original things in turn. This layout is relatively simple and can only put some simple things.

2、 LinearLayout

Linear layout, which can be understood as a div from the outer frame, is listed one by one on the screen from top to bottom. Each LinearLayout can be divided into vertical layout (Android: orientation = "vertical") and horizontal layout (Android: orientation = "horizontal"). In vertical layout, there is only one element in each row, and multiple elements are vertically downward in turn; In horizontal layout, there is only one row, and each element is arranged to the right in turn.

There is an important attribute Android: Layout in LinearLayout_ Weight = "1", which represents line spacing in vertical layout; Horizontal represents column width; The greater the weight value, the greater the weight.

3、 Absolutelayout

Absolute layout is like div, which specifies the absolute attribute. The X and Y coordinates are used to specify the position of the element. Android: Layout_ x="20px" android:layout_ Y = "12px" this layout method is also relatively simple, but there are often problems when switching vertically, and the calculation is troublesome when there are multiple elements.

4、 Relativelayout

Relative layout can be understood as a layout in which an element is used as a reference to locate. The main attributes are:

Relative to an element

android:layout_ Below = "@ ID / AAA" this element is in Android: layout with ID AAA_ Toleftof = "@ ID / BBB" change the left side of the element to BBB

Relative to the parent element

android:layout_ Alignparentleft = "true" align Android: layout on the left of the parent element_ Alignparentright = "true" align right on parent element

You can also specify margins, etc. see API for details

5、 Tablelayout

The table layout is similar to the table in HTML. Each tablelayout has a table row tablerow, which can specifically define each element and set its alignment. Android: gravity = "".

Each layout has its own suitable way. In addition, these five layout elements can be nested and applied to each other to make a beautiful interface.

This concludes all the tutorials in this article. I hope it will be helpful for you to learn the common layout of Android.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>