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)、点击运行,运行效果如下:

相关推荐
棒棒的唐10 小时前
发一个用本地AI(openclaw)写的调用本地llama.cpp服务对话,并按指定要求识别图片的PHP类
android·php·llama
_祝你今天愉快19 小时前
Android 事件传递机制:[二] 手写模拟事件分发
android
东坡大表哥1 天前
【Ubuntu】Ubuntu 20.04 LTS → 22.04 LTS 升级实录
android·linux·ubuntu
不要试图纠正别人1 天前
IdleHandler 一次都不跑,问题不在主线程忙
android·性能优化
bkspiderx1 天前
在Visual Studio中安装与配置Qt插件(Qt Visual Studio Tools)
ide·qt·visual studio·qt插件
booboosui1 天前
记忆装不下时谁删:500 条上限与每回合十行索引
android
好的佩奇2 天前
Dart 之 JSON
android·flutter·dart
_祝你今天愉快2 天前
Android 事件传递机制:[一] 事件分发机制详解
android
lusklusklusk2 天前
使用Visual Studio一步步创建并部署SSRS_PBIRS报表:数据源配置、图表设计、参数化查询、部署参数与排错实战
数据库·ide·visual studio
Digitally2 天前
如何将电脑上的联系人传输到安卓手机(4 种方法)
android