1. Layout overview
1 | Linear layout | Arrange horizontally and vertically |
2 | Relative layout | Arrange by relative positioning |
3 | frame layout | Open up a blank area, and the controls (layers) in the frame are superimposed |
4 | table layout | Tabular arrangement |
5 | Constraint layout | Write layouts visually |
2. Linear layout
1. Properties
android:id | unique value |
android:layout_height | high, wrap_content: (changes with the content, similar to auto), match_parent: (same as parent element) The unit is preferably: dp |
android:layout_width | wide, as above |
android:background | Background color |
android:layout_margin | Margin |
android:layout_padding | padding |
android:orientation | horizontal horizontal arrangement; vertical vertical arrangement |
android:layout_weight | View, equal weight |
android:gravity | Centered |
1. Horizontal arrangement android:orientation="horizontal"
<?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="horizontal"
>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮1"
android:layout_marginTop="20dp"
/>
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮2"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
/>
<Button
android:id="@+id/button3"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text="按钮3"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
/>
</LinearLayout>
1. Vertical arrangement android:orientation="vertical"
<?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"
>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮1"
android:layout_marginTop="20dp"
/>
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="按钮2"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
/>
<Button
android:id="@+id/button3"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text="按钮3"
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
/>
</LinearLayout>
.