【Android开发】考试系统
文章目录
一、开发环境需求
二、系统功能设计
三、运行结果
1. 欢迎界面
2. 主界面
3. 答题界面
四、主要代码
1. WelcomeActivity.java
代码如下:
package com.ssyw.exam2;
import com.ssyw.exam2.controller.WelcomeController;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.view.WindowManager;
import android.widget.ImageView;
public class WelcomeActivity extends BaseActivity {
//打开数据库
private WelcomeController wc=new WelcomeController();
private Handler mHandler = new Handler(); //创建handler对象
private ImageView iv_welcome; //创建视图对象
private int alpha = 255; //透明度
private int b = 0; //跳转标记
@SuppressLint("HandlerLeak")
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//全屏显示
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_welcome);
wc.init(this);
//绑定图像视图
iv_welcome=(ImageView) findViewById(R.id.iv_welcome);
//设置透明度
iv_welcome.setAlpha(alpha);
//创建线程并启动
new Thread(new Runnable() {
public void run() {
//初次进入标记点为0
while (b < 2) {
try {
if (b == 0) {
Thread.sleep(500);
b =1;
} else {
Thread.sleep(100);
}
//更新视图
updateApp();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}).start();
//接收handler消息
mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
iv_welcome.setAlpha(alpha); //设置透明度
iv_welcome.invalidate(); //界面刷新
}
};
}
public void updateApp() {
alpha -= 11;
//避免出现白屏
if (alpha <= 30) {
b = 2;//当透明度小于30时 跳转到住页面
Intent intent = new Intent(WelcomeActivity.this,MainTabActivity.class);
startActivity(intent);
this.finish();//关闭欢迎界面
//查询需要很多内存开销,提前回收一些
System.gc();
}//发送handler消息
mHandler.sendMessage(mHandler.obtainMessage());
}
}
2. activity_classics.xml
代码如下:
<<?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" >
<!--经典例题页面布局-->
<include
android:id="@+id/layout_title_style_1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
layout="@layout/layout_title_style_1" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="9" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/tv_classics_question"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/tv_classics_answer"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</ScrollView>
<Button
android:id="@+id/btn_classics_show_answer"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@drawable/bg_tab"
android:onClick="showAnswer"
android:text="@string/classics_show_answer" />
</LinearLayout>
以上是主要代码,完整文件可点击链接下载
https://download.youkuaiyun.com/download/qq_45647961/19662849