Android_shuzhifenxi_activitymain_zw

本文介绍了一个用于录入学生基本信息(包括班级、学号和姓名)的Android应用界面布局方案,并展示了具体的XML布局代码。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
    android:orientation="vertical"
    tools:context=".MainActivity"
    android:background="@color/layout">




    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">


        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="班级:"
            android:textSize="20sp" />


        <EditText
            android:id="@+id/et_class"
            android:layout_width="140dp"
            android:layout_height="wrap_content"
            android:textSize="20sp" />
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">


        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="学号:"
            android:textSize="20sp"/>


        <EditText
            android:id="@+id/et_number"
            android:layout_width="140dp"
            android:layout_height="wrap_content"
            android:textSize="20sp" />
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">


        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="姓名:"
            android:textSize="20sp"/>


        <EditText
            android:id="@+id/et_name"
            android:layout_width="140dp"
            android:layout_height="wrap_content"
            android:textSize="20sp" />
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">


       <Button
           android:id="@+id/btn_add"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:text="@string/app_button"
           android:textSize="20sp"
           android:background="@color/app_bk"/>
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="班级"
            android:textSize="20sp"/>
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="学号"
            android:textSize="20sp"/>
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="姓名"
            android:textSize="20sp"/>


    </LinearLayout>


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">


        <ListView
            android:id="@+id/listview"
            android:layout_width="match_parent"
            android:layout_height="match_parent"></ListView>


    </LinearLayout>


</LinearLayout>
Android Studio中创建`activity_main.xml`文件是为应用程序的主要活动设置布局的步骤。这个文件通常是应用启动的第一个界面,也称为启动屏幕或者主屏幕。以下是创建这个文件的简单步骤: 1. **打开项目结构**: - 打开你的Android项目,通常可以在"Project"或"Explorer"面板找到它。 - 导航到`res/layout`目录,这里存放所有应用程序的布局资源文件。 2. **创建新布局文件**: - 右键点击`layout`文件夹,选择 "New" -> "Layout resource file",或在菜单栏选择"File" > "New" > "Resource File"。 - 输入文件名,比如"activity_main",然后在弹出的对话框中选择"Activity"模板,最后点击"OK"。 3. **编辑XML内容**: - 打开刚创建的`activity_main.xml`文件,你会看到一个默认的空布局。在这里,你可以开始添加各种UI组件,如TextView、ImageView、Button等。 4. **添加视图**: - 使用XML标签添加需要的控件,例如: ```xml <androidx.appcompat.widget.AppCompatTextView android:id="@+id/main_title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="欢迎来到MainActivity!" /> ``` 5. **布局管理**: - 使用容器布局(如LinearLayout、RelativeLayout或ConstraintLayout)组织你的视图。 6. **保存文件**: - 完成布局设计后,记得保存文件。 现在你已经创建了一个基本的`activity_main.xml`文件,你可以在此基础上自定义你的应用程序界面布局。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

cf_matinal

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值