Layout:
There are a few common layouts that we use in Android:
1.LinearLayout (Linear layout): (There can only be one control inside, and cannot design the position of the control, the control will be placed in the upper left corner)
Linear layouts are divided into horizontal linear and vertical linear properties, respectively: android:orientation= "horizontal" android:orientation= "vertical".
2.RelativeLayout (Relative layout): (You can put multiple controls inside, but only one control on a line)
Additional classes of Relativelayout properties are available for your reference:
First Class: Property value is True or False
Android:layout_centerhrizontal Horizontal Center
Android:layout_centervertical Vertical Center
Android:layout_centerinparent is completely centered relative to the parent element
Android:layout_alignparentbottom snaps to the bottom edge of the parent element
Android:layout_alignparentleft snaps to the left edge of the parent element
Android:layout_alignparentright snaps to the right edge of the parent element
Android:layout_alignparenttop snaps to the top edge of the parent element
Android:layout_alignwithparentifmissing, if you can't find the brother element, use the parent element as a reference.
Second class: The attribute value must be the reference name of the id "@id/id-name"
Android:layout_below at the bottom of an element
Android:layout_above on top of an element
Android:layout_toleftof on the left side of an element
Android:layout_torightof on the right side of an element
Android:layout_aligntop aligns the top edge of this element with the top edge of an element
Android:layout_alignleft aligns the left edge of this element with the left edge of an element
Android:layout_alignbottom aligns the bottom edge of this element with the bottom edge of an element
Android:layout_alignright aligns the right edge of this element with the right edge of an element
Class III: Attribute values are specific pixel values, such as 30dip, 40px
Android:layout_marginbottom distance from the bottom edge of an element
Android:layout_marginleft distance from the left edge of an element
Android:layout_marginright distance from the right edge of an element
Android:layout_margintop distance from the top edge of an element
3.TableLayout (Table layout): (This is used in conjunction with TableRow, much like the table in HTML)
This table layout is not as flexible as the table in HTML, but only through the TableRow property to control its rows and columns, there are several controls in a few columns (typically). Such as:
<TableLayout>
<TableRow>
<EditText></EditText>
<EditText></EditText>
</TableRow>
<TableRow>
<EditText></EditText>
<EditText></EditText>
</TableRow>
</TableLayout>
Represents a table of two columns in two rows.
android:gravity= "Center" written explanation is weight ratio. The time is to let it center the display. It can also dynamically add each row inside each column. As shown in the following code:
/* Find table objects by ID */
Tablelayout tablelayout = (tablelayout) Findviewbyid (R.ID.TABLE01);
/* Create a Column object */
TableRow TableRow = new TableRow (this);
/* Text Box Object */
TextView temp = new TextView (this);
Temp.settext ("Value of text");
/* Add this text to the column */
Tablerow.addview (temp);
android:stretchcolumns= "1,2,3,4" means that the 1,2,3,4 column is automatically stretched.
4.AbsoluteLayout (Absolute layout): (You can put multiple controls inside, and you can define the location of the control's X, y)
5.FrameLayout (Frame layout): (You can put more than one control, but the position of the control is relative position)
The controls inside it are all displayed as one of the controls superimposed on the previous control, and all the elements are placed in the top left corner. Such as:
<framelayout android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content" android:layout_weight= "1" >
<imageview android:id= "@+id/iv1" android:layout_width= "Wrap_content"
android:layout_height= "wrap_content" android:visibility= "Invisible"
android:src= "@drawable/lotusleaf" ></ImageView>
<imageview android:id= "@+id/f1" android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content" android:src= "@drawable/frog_right"
android:visibility= "Invisible" ></ImageView>
</FrameLayout>
Represents a control with ID F1 superimposed on a control with ID IV1
(LinearLayout and Relativelayout should be more than two of them.) Absolutelayout is less used because it is laid out according to the absolute position of the screen, and the position of the control changes if the screen size changes. This is equivalent to the absolute layout of the HTML, it is generally not recommended)
Android Interface Layout