手机app开发1.基础显示控件

前言

我认为教是最好的学,所以制作这一刊,自己自学制作手机app软件。

创建工程

选择一个空的工程创建

编译测试

首先先成功实现Hellow world

首先在res里面创建一个layout布局

然后定义一个这样的结构类

<?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:id="@+id/main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/red"
    tools:context=".MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@color/green"
        android:shadowColor="@color/white"
        android:text="Hello World!"
        android:textColor="@color/red"
        android:textColorLink="@color/red"
        android:textSize="40sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        tools:ignore="TextContrastCheck" />

</androidx.constraintlayout.widget.ConstraintLayout>

最上面的内容是总体布局

比如  android:background="@color/red"

那么就是让总体背景红色


   

androidx.constraintlayout.widget.ConstraintLayout:这是根布局,ConstraintLayout 是 Android 提供的一个强大的布局管理器,用于创建复杂的布局。


xmlns:android、xmlns:app、xmlns:tools:这些是命名空间声明,分别用于 Android 系统属性、自定义属性和工具属性。


android:id="@+id/main":为布局设置一个唯一的标识符 main。
android:layout_width="match_parent" 和 android:layout_height="match_parent":设置布局的宽度和高度与父容器相同。


android:background="@color/red":设置布局的背景颜色为红色,@color/red 是引用了颜色资源文件中定义的红色。


tools:context=".MainActivity":这是一个工具属性,用于告诉 Android Studio 这个布局文件与 MainActivity 相关联。

下面的是我的文字的内容

android:layout_width="wrap_content" 和 android:layout_height="wrap_content":设置 TextView 的宽度和高度根据其内容自动调整。


android:background="@color/green":设置 TextView 的背景颜色为绿色。


android:shadowColor="@color/white":设置文字阴影的颜色为白色。


android:text="Hello World!":设置 TextView 显示的文本内容为 "Hello World!"。


android:textColor="@color/red":设置文本的颜色为红色。


android:textColorLink="@color/red":设置文本中链接的颜色为红色。


android:textSize="40sp":设置文本的字体大小为 40 缩放像素(sp)。


app:layout_constraintBottom_toBottomOf="parent"、

app:layout_constraintEnd_toEndOf="parent"、app:layout_constraintStart_toStartOf="parent"、

app:layout_constraintTop_toTopOf="parent":这些约束条件将 TextView 居中显示在父布局中。


tools:ignore="TextContrastCheck":这是一个工具属性,用于忽略 Android Studio 的文本对比度检查警告。