基本视图组件和布局管理的使用(用户注册界面设计——计算器界面设计)

一、作业要求

  1. minSDKVersion=24,targetSDK=30
  2. 本次所有上机作业整合一份word文档通过学习通APP提交,文档的名字为”学号姓名”如18101123张三.doc。

二、上机作业

用户注册界面设计

已知注册界面如图1所示,分别用LinearLayout、TableLayout或ConstraintLayout,布局管理器去设计,基本组件有TextView、Button、EditText、RadioButton、RadioGroup和CheckBox;其中界面中的图标是包含在TextView组件中,使用该组件的android:drawableLeft属性设置的。而所用到的图标都是由Android Material Design Icon Generator插件产生的。在使用图标前先安装该插件,具体步骤为在Android Studio中 File->setting->plugins->Browse Repositories弹出窗口中输入Android Material Design Icon Generator,然后点击窗体内右面的INSTALL安装即可。创建图标步骤:File->new->Material design icon,选择所需的图标,默认会将产的图标存储在res/drawable目录下。
在这里插入图片描述

1、LinearLayout布局管理器设计的注册界面

(1)res/layout/布局文件名.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">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="用户注册"
        android:gravity="center"
        android:textSize="30sp"/>
    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="2"
            android:drawableLeft="@drawable/account_18dp"
            android:gravity="center"
            android:text="用户名:" />

        <EditText
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="7"
            android:text="Name"/>
    </LinearLayout>
    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <TextView
            android:drawableLeft="@drawable/password_18dp"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="2"
            android:gravity="center"
            android:text="新密码:"/>

        <EditText
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="7"
            android:text=""/>
    </LinearLayout>
    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <TextView
            android:drawableLeft="@drawable/key_18dp"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="2"
            android:gravity="center"
            android:text="确认密码:"/>

        <EditText
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="7"
            android:text=""/>
    </LinearLayout>
    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <TextView
            android:drawableLeft="@drawable/date_18dp"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="2"
            android:gravity="center"
            android:text="出生年月:"/>

        <EditText
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="7"
            android:text=""/>
    </LinearLayout>
    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <TextView
            android:drawableLeft="@drawable/phone_18dp"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="2"
            android:gravity="center"
            android:text="电话:"/>

        <EditText
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="7"
            android:text=""/>
    </LinearLayout>
    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <TextView
            android:drawableLeft="@drawable/baseline_home_black_18dp"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="2"
            android:gravity="center"
            android:text="家庭地址:"/>

        <EditText
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="7"
            android:text=""/>
    </LinearLayout>
    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <TextView
            android:drawableLeft="@drawable/email_18dp"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="2"
            android:gravity="center"
            android:text="E_mail:"/>

        <EditText
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="7"
            android:text=""/>
    </LinearLayout>
    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <TextView
            android:drawableLeft="@drawable/gender_18dp"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center"
            android:text="性别:"/>
        <RadioGroup
            android:orientation="horizontal"
            android:id="@+id/radioGroup_1"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="4">
            <RadioButton
                android:id="@+id/radioButton_1"
                android:layout_width="50dp"
                android:layout_height="match_parent"
                android:text=""/>
            <RadioButton
                android:id="@+id/radioButton_2"
                android:layout_width="50dp"
                android:layout_height="match_parent"
                android:text=""/>
        </RadioGroup>
    </LinearLayout>
    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <TextView
            android:drawableLeft="@drawable/gender_18dp"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center"
            android:text="兴趣:"/>
        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="4">
            <CheckBox
                android:id="@+id/checkbox_1"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="4"
                android:text="游泳">
            </CheckBox>
            <CheckBox
                android:id="@+id/checkbox_2"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="4"
                android:text="打篮球">
            </CheckBox>
            <CheckBox
                android:id="@+id/checkbox_3"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="4"
                android:text="滑雪">
            </CheckBox>
            <CheckBox
                android:id="@+id/checkbox_4"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="4"
                android:text="画画">
            </CheckBox>
        </LinearLayout>
    </LinearLayout>
</LinearLayout>

2、ConstraintLayout布局管理器设计的注册界面


            android:layout_height="wrap_content"
            android:id="@+id/guideline8"
            android:orientation="horizontal"
            app:layout_constraintGuide_percent="0.45" />

    <TextView
            android:text="E_mail:"
            android:drawableLeft="@drawable/email_18dp"
            android:layout_width="150dp"
            android:layout_height="40dp"
            android:id="@+id/textView10"
            android:textSize="25sp"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintTop_toBottomOf="@id/guideline8"
            app:layout_constraintBottom_toTopOf="@id/guideline9"
            android:layout_marginTop="5dp"
            android:layout_marginBottom="5dp" />

    <EditText
            android:layout_width="300dp"
            android:layout_height="40dp"
            android:textSize="18sp"
            app:layout_constraintLeft_toRightOf="@id/textView10"
            app:layout_constraintTop_toBottomOf="@id/guideline8"
            app:layout_constraintBottom_toTopOf="@id/guideline9"
            app:layout_constraintRight_toRightOf="parent"
            android:layout_marginTop="5dp"
            android:layout_marginBottom="5dp" />
    <androidx.constraintlayout.widget.Guideline
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/guideline9"
            android:orientation="horizontal"
            app:layout_constraintGuide_percent="0.52" />

    <TextView
            android:text="性别:"
            android:drawableLeft="@drawable/gender_18dp"
            android:layout_width="150dp"
            android:layout_height="40dp"
            android:id="@+id/textView11"
            android:textSize="25sp"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintTop_toBottomOf="@id/guideline9"
            app:layout_constraintBottom_toTopOf="@id/guideline10"
            android:layout_marginTop="5dp"
            android:layout_marginBottom="5dp" />

    <RadioGroup
            android:orientation="horizontal"
            android:id="@+id/radioGroup_1"
            android:layout_width="300dp"
            android:layout_height="40dp"
            app:layout_constraintLeft_toRightOf="@id/textView11"
            app:layout_constraintTop_toBottomOf="@id/guideline9"
            app:layout_constraintBottom_toTopOf="@id/guideline10"
            app:layout_constraintRight_toRightOf="parent"
            android:layout_marginTop="5dp"
            android:layout_marginBottom="5dp">

        <RadioButton
                android:id="@+id/radioButton_1"
                android:layout_width="50dp"
                android:layout_height="match_parent"
                android:text="" />

        <RadioButton
                android:id="@+id/radioButton_2"
                android:layout_width="50dp"
                android:layout_height="match_parent"
                android:text="" />
    </RadioGroup>
    <androidx.constraintlayout.widget.Guideline
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/guideline10"
            android:orientation="horizontal"
            app:layout_constraintGuide_percent="0.59" />

    <TextView
            android:text="兴趣:"
            android:drawableLeft="@drawable/gender_18dp"
            android:layout_width="150dp"
            android:layout_height="40dp"
            android:id="@+id/textView12"
            android:textSize="25sp"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintTop_toBottomOf="@id/guideline10"
            app:layout_constraintBottom_toTopOf="@id/guideline11"
            android:layout_marginTop="5dp"
            android:layout_marginBottom="5dp" />
    <LinearLayout
            android:layout_width="300dp"
            android:layout_height="40dp"
            app:layout_constraintLeft_toRightOf="@id/textView12"
            app:layout_constraintTop_toBottomOf="@id/guideline10"
            app:layout_constraintBottom_toTopOf="@id/guideline11"
            app:layout_constraintRight_toRightOf="parent"
            android:layout_marginStart="3dp"
            android:layout_marginTop="5dp"
            android:layout_marginBottom="5dp">
        <CheckBox
                android:id="@+id/checkbox_1"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="4"
                android:text="游泳">
        </CheckBox>
        <CheckBox
                android:id="@+id/checkbox_2"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="4"
                android:text="打篮球">
        </CheckBox>
        <CheckBox
                android:id="@+id/checkbox_3"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="4"
                android:text="滑雪">
        </CheckBox>
        <CheckBox
                android:id="@+id/checkbox_4"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="4"
                android:text="画画">
        </CheckBox>
    </LinearLayout>
    <androidx.constraintlayout.widget.Guideline
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/guideline11"
            android:orientation="horizontal"
            app:layout_constraintGuide_percent="0.66" />
</androidx.constraintlayout.widget.ConstraintLayout>

(二)、计算器界面设计

请使用布局管理器ConstraintLayout设计计算器的界面如图2所示,基本组件有TextView、Button。
在这里插入图片描述

(1)res/layout/布局文件名.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">
        <TextView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:text="0"
                android:textSize="100sp"
                android:gravity="right"
                app:layout_constraintTop_toBottomOf="parent"
                app:layout_constraintBottom_toTopOf="@id/guideline5"/>
    <androidx.constraintlayout.widget.Guideline
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/guideline5"
            android:orientation="horizontal"
            app:layout_constraintGuide_percent="0.20"/>
    <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="80dp"
            app:layout_constraintTop_toBottomOf="@id/guideline5"
            app:layout_constraintBottom_toTopOf="@id/guideline6">
        <TextView
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:gravity="center"
                android:text="MC"
                android:textSize="30sp"/>
        <TextView
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:gravity="center"
                android:text="MR"
                android:textSize="30sp"/>
        <TextView
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:gravity="center"
                android:text="M+"
                android:textSize="30sp"/>
        <TextView
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:gravity="center"
                android:text="M-"
                android:textSize="30sp"/>
        <TextView
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:gravity="center"
                android:text="MS"
                android:textSize="30sp"/>
        <TextView
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:gravity="center"
                android:text="M*"
                android:textSize="30sp"/>
    </LinearLayout>
    <androidx.constraintlayout.widget.Guideline
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/guideline6"
            android:orientation="horizontal"
            app:layout_constraintGuide_percent="0.30"/>
    <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="80dp"
            app:layout_constraintTop_toBottomOf="@id/guideline6"
            app:layout_constraintBottom_toTopOf="@id/guideline7">
        <TextView
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:gravity="center"
                android:text="%"
                android:textSize="30sp"/>
        <TextView
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:gravity="center"
                android:text=""
                android:textSize="30sp"/>
        <TextView
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:gravity="center"
                android:text=""
                android:textSize="30sp"/>
        <TextView
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:gravity="center"
                android:text="1/x"
                android:textSize="30sp"/>
    </LinearLayout>
    <androidx.constraintlayout.widget.Guideline
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/guideline7"
            android:orientation="horizontal"
            app:layout_constraintGuide_percent="0.40"/>
        <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="80dp"
                android:orientation="horizontal"
                app:layout_constraintTop_toTopOf="@id/guideline7"
                app:layout_constraintBottom_toTopOf="@id/guideline0">
            <TextView
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:gravity="center"
                android:text="C"
                android:textSize="30sp"/>
            <TextView
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:text="+/-"
                    android:textSize="30sp"/>
            <TextView
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:text="%"
                    android:textSize="30sp"/>
            <TextView
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:text="÷"
                    android:textSize="30sp"/>
        </LinearLayout>
        <androidx.constraintlayout.widget.Guideline
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:id="@+id/guideline0"
                android:orientation="horizontal"
                app:layout_constraintGuide_percent="0.50"/>

        <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="80dp"
                android:orientation="horizontal"
                app:layout_constraintTop_toBottomOf="@id/guideline0"
                app:layout_constraintBottom_toTopOf="@id/guideline1">
            <TextView
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:text="1"
                    android:textSize="30sp"/>
            <TextView
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:text="2"
                    android:textSize="30sp"/>
            <TextView
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:text="3"
                    android:textSize="30sp"/>
            <TextView
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:text="X"
                    android:background="#F8872E"
                    android:textSize="30sp"/>
        </LinearLayout>
    <androidx.constraintlayout.widget.Guideline
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/guideline1"
            android:orientation="horizontal"
            app:layout_constraintGuide_percent="0.60"/>
    <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="80dp"
            android:orientation="horizontal"
            app:layout_constraintTop_toBottomOf="@id/guideline1"
            app:layout_constraintBottom_toTopOf="@id/guideline2">
        <TextView
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:gravity="center"
                android:text="4"
                android:textSize="30sp"/>
        <TextView
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:gravity="center"
                android:text="5"
                android:textSize="30sp"/>
        <TextView
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:gravity="center"
                android:text="6"
                android:textSize="30sp"/>
        <TextView
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:gravity="center"
                android:background="#F8872E"
                android:text="-"
                android:textSize="30sp"/>
    </LinearLayout>
    <androidx.constraintlayout.widget.Guideline
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/guideline2"
            android:orientation="horizontal"
            app:layout_constraintGuide_percent="0.70"/>
    <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="80dp"
            android:orientation="horizontal"
            app:layout_constraintTop_toBottomOf="@id/guideline2"
            app:layout_constraintBottom_toTopOf="@id/guideline3">
        <TextView
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:gravity="center"
                android:text="7"
                android:textSize="30sp"/>
        <TextView
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:gravity="center"
                android:text="8"
                android:textSize="30sp"/>
        <TextView
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:gravity="center"
                android:text="9"
                android:textSize="30sp"/>
        <TextView
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:gravity="center"
                android:background="#F8872E"
                android:text="+"
                android:textSize="30sp"/>
    </LinearLayout>
    <androidx.constraintlayout.widget.Guideline
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/guideline3"
            android:orientation="horizontal"
            app:layout_constraintGuide_percent="0.80"/>
    <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="80dp"
            android:orientation="horizontal"
            app:layout_constraintTop_toBottomOf="@id/guideline3"
            app:layout_constraintBottom_toTopOf="@id/guideline4">
        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="2"
            android:text="±"
            android:gravity="center"
            android:textSize="30sp"/>
        <TextView
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="2"
                android:text="0"
                android:gravity="center"
                android:textSize="30sp"/>
        <TextView
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="2"
                android:text="."
                android:gravity="center"
                android:textSize="30sp"/>
        <TextView
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="2"
                android:text="="
                android:background="#F8872E"
                android:gravity="center"
                android:textSize="30sp"/>
    </LinearLayout>
    <androidx.constraintlayout.widget.Guideline
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/guideline4"
            android:orientation="horizontal"
            app:layout_constraintGuide_percent="0.90"/>
</androidx.constraintlayout.widget.ConstraintLayout>
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值