android studio 日志 (二)用LinearLayout设计一个简单的学生信息录入界面

承接日志一,在新建的项目中设计一个简单的界面

最终效果图
在这里插入图片描述
首先打开已经创建好的activity_main.xml文件
在这里插入图片描述
在页面上写代码,我用的是基础的LinearLayout,并嵌套使用,使得界面横竖有序,更为好看

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >//竖列
    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textSize="20sp"
        android:text="@string/hello"/> <!--strings.xml文件中设置-->
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal">横列
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical">//嵌套竖列
            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:textSize="25sp"
                android:text="@string/name"
                />
            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:textSize="25sp"
                android:text="@string/sex"
                />

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="@string/age"
                android:textSize="25sp" />
        </LinearLayout>
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">
            <EditText
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:id="@+id/edit1"
                android:inputType="text"
                android:textSize="8dp"
                />
            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">

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

                    <RadioButton
                        android:id="@+id/boy01"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="@string/boy" />

                    <RadioButton
                        android:id="@+id/girl01"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="@string/girl" />
                </RadioGroup>
            </LinearLayout>
            <EditText
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:id="@+id/edit2"
                android:inputType="text"
                android:textSize="11dp"
                />
        </LinearLayout>
    </LinearLayout>
    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textSize="20sp"
        android:text="@string/hobby"
        />
    <CheckBox
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/check1"
        android:textSize="20sp"
        android:text="@string/basketball"
        />
    <CheckBox
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/check2"
        android:textSize="20sp"
        android:text="@string/football"
        />
    <CheckBox
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/check3"
        android:textSize="20sp"
        android:text="@string/music"
        />
    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/ok"
        android:text="@string/ok"
        />
    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/message"
        android:text=""
        />
</LinearLayout>

完成后如下图所示
在这里插入图片描述
会看到界面上没有显示所要的文字,这是因为还要在strings.xml设置name(这样做是为了以后管理更简洁,而且切换语言版本也更方便)
打开strings.xml,设置想要改的名称
在这里插入图片描述

<resources>
    <string name="app_name">test</string>
    <string name="hello">学生信息录入</string>  //“学生信息录入”就是要改的名字
    <string name="name">姓名:</string>
    <string name="sex">性别:</string>
    <string name="age">年龄:</string>
    <string name="hobby">业余爱好</string>
    <string name="boy">男</string>
    <string name="girl">女</string>
    <string name="basketball">篮球</string>
    <string name="football">足球</string>
    <string name="music">音乐</string>
    <string name="ok">确定</string>
</resources>

然后运行,即可完成一个简单的界面
(偷懒没有写按钮监听代码)
在这里插入图片描述

  • 7
    点赞
  • 42
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值