安卓Day6实训项目:学生信息管理系统V1.0

一.知识点总结

(思维导图我们华老师总结的,放在这里,以防找不到)

二.实训项目

1.创建一个安卓项目

  • 基于Empty Activity 创建安卓项目
    在这里插入图片描述

  • 单击Finish后出现的界面
    在这里插入图片描述

  • 将MainActivity改名为SplashScreenActivity
    在这里插入图片描述

  • 将对应的activity_main.xml改名为activity_splash_screen.xml

2.准备图片

  • 准备三种图片放到mipmap中
    在这里插入图片描述

3.创建启动界面

(1)启动布局资源文件

  • 布局资源文件activity_splash_screen
    在这里插入图片描述
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/root_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@mipmap/splash_back"
    android:gravity="center_vertical|center_horizontal">

    <ImageView
        android:id="@+id/iv_student"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@mipmap/student" />

    <TextView
        android:id="@+id/tv_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="#0000ff"
        android:textSize="30sp"
        android:layout_marginTop="20dp"
        android:text="@string/title" />

    <TextView
        android:id="@+id/tv_version"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="#ff0000"
        android:layout_marginTop="20dp"
        android:textSize="20sp"
        android:text="@string/version" />

</LinearLayout>
  • 有两处报错,需要在字符串资源文件里面定义两个变量

(2)字符串资源文件中定义字符串变量

-String.xml中
在这里插入图片描述

(3)创建动画配置文件

  • 在res目录里创建anim子目录,在子目录里创建自定义动画资源animator.xml
    在这里插入图片描述
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <alpha
        android:duration="3000" 
        android:fromAlpha="0.0"
        android:toAlpha="1.0" />

    <rotate
        android:duration="3000" 
        android:fromDegrees="0"
        android:interpolator="@android:anim/accelerate_decelerate_interpolator"
        android:pivotX="50%" 
        android:pivotY="50%"  
        android:toDegrees="+360" /> 
</set>

(4)编写启动界面类

  • 启动界面类 - SplashScreenActivity
    在这里插入图片描述
package net.yuanjing.student_management;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.LinearLayout;

public class SplashScreenActivity extends AppCompatActivity {
    private Animation animation;  //动画对象
    private ImageView ivStudent; //学生图像视图
     private LinearLayout rootLayout; //根布局
    private final int DELAY_TIME = 400; //延迟时间

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //利用资源布局文件设置用户界面
        setContentView(R.layout.activity_splash_screen);
        //通过资源标识符获取控件实例
        ivStudent = findViewById(R.id.iv_student);
        rootLayout = findViewById(R.id.root_layout);
        //创建动画对象
        animation = AnimationUtils.loadAnimation(this, R.anim.animator);
        //启动动画
        ivStudent.startAnimation(animation);
        
        //窗口单机事件处理
        rootLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //创建一个意图
                Intent intent = new Intent(SplashScreenActivity.this,LoginActivity.class);
                //按照意图跳转到登录界面
                startActivity(intent);
                //关闭启动界面
                finish();
            }
        });
        
        //利用消息处理器实现延迟操作
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                //创建一个意图
                Intent intent = new Intent(SplashScreenActivity.this,LoginActivity.class);
                //按照意图跳转到登录界面
                startActivity(intent);
                //关闭启动界面
                finish();
            }
        },DELAY_TIME); //匿名对象,用一次就没了
    }
}
  • 目前,程序报错,是因为还没有创建登录界面LoginActivity
    在这里插入图片描述
  • 在创建子包ui
    在这里插入图片描述
  • 此时可以先创建一个空的登录界面,这样可以测试启动界面的运行效果
  • 基于模板创建- LoginActivity 放在ui子包中

在这里插入图片描述

  • 查看安卓项目清单文件
    在这里插入图片描述

(5)启动应用,查看效果

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值