


Empty Activity创建安卓项目 - StudentManagement

MainActivity改名为SplashScreenActivity
activity_main.xml改名为activity_splash_screen.xml
mipmap目录里
activity_splash_screen.xml
<?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>
strings.xml
<resources>
<string name="app_name">学生信息管理系统V1.0</string>
<string name="title">学生信息管理系统</string>
<string name="version">Version 1.0</string>
</resources>
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>
SplashScreenActivity
package net.huawei.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 = 4000; // 延迟时间
@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 v) {
// 创建意图
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尚未创建
net.huawei.student_management包里创建ui子包
ui子包
ui子包里基于模板创建登录界面 - LoginActivity


