android studio 创建按钮项目

1)、新建一个empty activity项目,切换到project视图:

2)、修改app\src\main\res\layout\activity_main.xml文件,修改后如下:

<?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:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello everyone!"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="@+id/button"
        app:layout_constraintStart_toStartOf="@+id/button"
        app:layout_constraintTop_toTopOf="parent" />

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="开灯"
        app:layout_constraintBottom_toTopOf="@+id/textView"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

3)、点击运行,运行效果如下:

相关推荐

  1. AndroidStudio

    2023-12-18 01:24:02       63 阅读
  2. ABAP 选择屏幕创建按钮,并执行

    2023-12-18 01:24:02       50 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2023-12-18 01:24:02       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2023-12-18 01:24:02       100 阅读
  3. 在Django里面运行非项目文件

    2023-12-18 01:24:02       82 阅读
  4. Python语言-面向对象

    2023-12-18 01:24:02       91 阅读

热门阅读

  1. LeetCode 15 三数之和

    2023-12-18 01:24:02       55 阅读
  2. 1131 - 删除指定字符

    2023-12-18 01:24:02       57 阅读
  3. DockerFile

    2023-12-18 01:24:02       55 阅读
  4. vi/vim的工作模式

    2023-12-18 01:24:02       59 阅读
  5. Android - 分区存储 MediaStore、SAF

    2023-12-18 01:24:02       58 阅读
  6. 【NTN 卫星通信】Starlink,费用、服务、市场(二)

    2023-12-18 01:24:02       169 阅读
  7. (第23天)Oracle 数据泵用户导出导入

    2023-12-18 01:24:02       58 阅读
  8. 自然语言处理(NLP)技术

    2023-12-18 01:24:02       55 阅读
  9. 视频-帧数-FPS

    2023-12-18 01:24:02       63 阅读