1. Linear layout LinerLauout
The linear layout can be a single row and column view. Rows can be horizontal or vertical;
you can useandroid:orientation
Attributes | parameter |
---|---|
android:orientation | horizonal和vertical |
android:width | wrap_content和match_parent |
adnroid:width | wrap_content和match_parent |
linelayout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFFAF0"
android:gravity="center"
android:text="TextView(显示框)"
android:textColor="#EA5246"
android:textSize="18sp"
android:textStyle="bold|italic" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FF4500"
android:gravity="center"
android:text="TextView(显示框)"
android:textColor="#EA5246"
android:textSize="18sp"
android:textStyle="bold|italic" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#808080"
android:gravity="center"
android:text="TextView(显示框)"
android:textColor="#EA5246"
android:textSize="18sp"
android:textStyle="bold|italic" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#000000"
android:gravity="center"
android:text="TextView(显示框)"
android:textColor="#EA5246"
android:textSize="18sp"
android:textStyle="bold|italic" />
</LinearLayout>
2. Table Layout TableLayout
TableRow
Determine the number of rows, the number of columns in it
tablelayout.xml
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TableRow>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="测试11" />
</TableRow>
<TableRow>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="测试21" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="测试22" />
</TableRow>
<TableRow>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="测试31" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="测试32" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="测试33" />
</TableRow>
</TableLayout>
3. Frame Layout FrameLayout
The secondary layout is used to add views from bottom to top in the Lacey stack format, which is to cover layer by layer.
framelayout.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center" >
<TextView
android:layout_width="150sp"
android:layout_height="150sp"
android:background="#000000"
android:gravity="center"
/>
<TextView
android:layout_width="100sp"
android:layout_height="100sp"
android:background="#FFA07A"
android:gravity="center"
/>
<TextView
android:layout_width="50sp"
android:layout_height="50sp"
android:background="#FFD700"
android:gravity="center"
/>
</FrameLayout>
4. Relative Layout RelativeLayout
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="${relativePackage}.${activityClass}" >
<Button
android:id="@+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
</RelativeLayout>
5. Absolute layout RelativeLayout
The layout is definitely not recommended, so you don’t need to watch it
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="42dp"
android:layout_y="92dp"
android:text="CheckBox" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="22dp"
android:layout_y="14dp"
android:text="Button" />
</AbsoluteLayout>