Android常见界面布局

界面简介

界面通常由容器控件构成。容器一般是手机屏幕,控件是实现功能的图形元素。

布局文件是activity_main.xml,采用xml格式开发。

  1. 进入activity_main.xml,如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="道坤的第一个程序!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
image-20230410195043629

layout_widthlayout_height有三种参数:

  • match_parent 与父容器相匹配
  • wrap_content 环绕内容
  • fill_heighth 填充内容

TextView的属性中,距离单位dp与设备硬件无关设置字体大小用sp。

相对父容器布局