关于如何编写hello world程序已经有很多,本文章主要是新版新手熟悉AS,如何打开layout视图

如果没有layout视图,文中有解决方法

1、点击快捷方式

2、点击empty activity——next

3、Save location目录,每次都需要重新创建;language选择java;点击finish完成

4、点击project查看是否如图视窗

若果不是如图视窗,说明安装少了一些文件,根据提示安装,AS的视窗会给出网址,作者当初新安装gradle-7.2-bin.zip这个文件,没有exe文件,是复制到安装目录,如果有exe直接运行即可

5、新建新的layout布局

6、设置名字

7、回到第一个文件,可见如图显示

 此处有两个文件第一个是创建应用系统生成的,第二个 是刚新建的

点击第一个布局

这里design视图直接有helloworld code是编码

点击code可查看代码段

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android/apk/res/android"
    xmlns:app="http://schemas.android/apk/res-auto"
    xmlns:tools="http://schemas.android/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="Hello World!"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

更多推荐

Android Studio编写Hello world