布局
- xmln是命名空间
- sp是设置字体的大小
线性布局
- 将组件水平或者垂直排列
实例
<?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/mButton1"
android:layout_width="60px"
android:layout_height="wrap_content"
android:text="按钮1">
</Button>
<Button
android:id="@+id/mButton2"
android:layout_width="60px"
android:layout_height="wrap_content"
android:text="按钮2">
</Button>
<Button
android:id="@+id/mButton3"
android:layout_width="60px"
android:layout_height="wrap_content"
android:text="按钮3">
</Button>
<Button
android:id="@+id/mButton4"
android:layout_width="60px"
android:layout_height="wrap_content"
android:text="按钮4">
</Button>
</LinearLayout>
帧布局
- 将组件放在左上角的位置,当添加多个组件后面的组件将覆盖之前的组件
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/mImageView">
</ImageView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="4011花果山"
android:textSize="18sp">
</TextView>
</FrameLayout>
package com.example.liearlayout;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import