Android is very crazy now, so the information about Android learning on the Internet is springing up like mushrooms after a rain. There are so many basic things like these. I will record the difficulties encountered by using things and how to solve them. In order to review, if I encounter similar problems again in the future, I can take them directly. Secondly, it can help beginners a little help.
Android layout is an important part of application interface development. In Android, there are five layout methods, namely: FrameLayout
Bureau), LinearLayout (linear layout), AbsoluteLayout (absolute layout), RelativeLayout (relative layout), TableLayout (table layout)
1. FrameLayout
This layout can be seen as a pile of things at the bottom of the wall, with a square rectangular upper left corner of the wall. If we place the first thing, we need to put another one, and then put it on the original place. If we place it in sequence, it will cover the original thing. This layout is relatively simple, and you can only put some simple things.
2. LinearLayout
Linear layout, this thing, can be understood as a div from the outer frame, first of all, it is listed one by one on the screen from top to bottom. Each LinearLayout can be divided into vertical layouts
(android:orientation="vertical") and horizontal layout (android:orientation="horizontal"
). When laid out vertically, there is only one element in each row, and multiple elements go down vertically in sequence; when laid out horizontally, there is only one line, and each element is arranged to the right in sequence.
There is an important attribute in linearLayout android:layout_weight="1". When this weight is laid out vertically, it represents the row spacing; when it is horizontal, it represents the column width; the larger the weight value, the larger the larger.
3. AbsoluteLayout
Absolute layout is like a div that specifies absolute attribute, using X and Y coordinates to specify the position of the element android:layout_x="20px"
Android:layout_y="12px" is also relatively simple, but when switching vertically, problems often occur, and when multiple elements are used, calculations are more troublesome.
4. RelativeLayout
Relative layout can be understood as a layout method where a certain element is a reference object to position it. The main attributes are:
Relative to a certain element
android:layout_below="@id/aaa" This element is below the id of aaa
android:layout_toLeftOf="@id/bbb" Change the left side of the element is bbb
Relative to the parent element
android:layout_alignParentLeft="true" Align left on parent element
android:layout_alignParentRight="true" right-aligned on parent element
You can also specify margins, etc., please refer to the API for details.
5. TableLayout
The table layout is similar to the Table in Html. Each TableLayout has a table row TableRow. TableRow can specifically define each element and set its alignment method android:gravity="" .
Each layout has its own suitable method. In addition, these five layout elements can be nested and applied to each other to create a beautiful interface.
At this point, all the tutorials in this article end here. I hope it will be helpful for everyone to learn common layouts of Android.