作业总要求
使用附件“素材”压缩包中的素材完成下列任务:

1.完成小游戏主程序,如图mainActivity.png。

2.在主程序界面当按下游戏介绍按钮时进行游戏介绍界面如图gameintroduce.png,按“返回”按钮则回到主程序界面。

3.在主程序界面按下“进入游戏”按钮则进入游戏界面如图gameScores.png,按“返回”按钮加回主界面同时将子程序界面中的游戏成绩返回到主程序并显示在主程序中如图mainActivity1.png所示。

4.提交程序运行视频
5.所有相关的Java和XML文件。

思路:

一个主页面,四个子页面

主页面

MainActivity.class

package com.example.myapplication1;

import android.content.Intent;
import android.os.Bundle; import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity; import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView; public class MainActivity extends AppCompatActivity { private ImageView imageView1;
private ImageView imageView2;
private ImageView imageView3;
private ImageView imageView4;
private TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageView1=findViewById(R.id.imageView);
imageView2=findViewById(R.id.imageView2);
imageView3=findViewById(R.id.imageView3);
imageView4=findViewById(R.id.imageView4);
textView=findViewById(R.id.textView);
imageView1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startActivityForResult(new Intent(MainActivity.this,
GameintroduceActivity.class),1);
}
}); imageView2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startActivityForResult(new Intent(MainActivity.this,
Entergame.class),2);
}
}); imageView3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startActivityForResult(new Intent(MainActivity.this,
Archivedownload.class),3);
}
}); imageView4.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startActivityForResult(new Intent(MainActivity.this,
Designintroduce.class),4);
}
}); } @Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode){
case 1:
{assert data != null;
String position = data.getStringExtra("position1");
textView.setText(position);
break;}
case 2:{
assert data != null;
String position = data.getStringExtra("position2");
textView.setText(position);
break;}
case 3:{
assert data != null;
String position = data.getStringExtra("position3");
textView.setText(position);
break;} case 4:{
assert data != null;
String position = data.getStringExtra("position4");
textView.setText(position);
break;} default:
{textView.setText("");
break;}
}
}
}

activity_main.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:background="@drawable/gameface"
android:gravity="center"
android:orientation="vertical"> <ImageView
android:id="@+id/imageView" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
app:srcCompat="@drawable/introduce" /> <ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
app:srcCompat="@drawable/startgame" /> <ImageView
android:id="@+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
app:srcCompat="@drawable/icon_load" /> <ImageView
android:id="@+id/imageView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
app:srcCompat="@drawable/icon_works" /> <TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="60dp"
android:layout_weight="4"
/>
</LinearLayout>

游戏介绍界面

GameIntroduceActivity.class

package com.example.myapplication1;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView; public class GameintroduceActivity extends AppCompatActivity {
private TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.gameintroduce);
textView=findViewById(R.id.textView2);
textView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = getIntent();
String s = textView.getText().toString();
intent.putExtra("position1", s);
setResult(RESULT_OK,intent);
finish();
}
});
}
}

gameintroduce.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:background="@drawable/game1"
tools:context=".GameintroduceActivity"> <TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="这是游戏介绍"
android:textColor="#DC143C"
android:textSize="60dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
/>
</RelativeLayout>

进入游戏界面

Entergame.class

package com.example.myapplication1;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView; public class Entergame extends AppCompatActivity {
private TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_entergame);
textView=findViewById(R.id.textView3);
textView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = getIntent();
String s = textView.getText().toString();
intent.putExtra("position2", s);
setResult(RESULT_OK,intent);
finish();
}
});
}
}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:background="@drawable/game2"
tools:context=".Entergame"> <TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#DC143C"
android:textSize="60dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="获得游戏分数3600" />
</RelativeLayout>

存档界面

Archivedownload.class

package com.example.myapplication1;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView; public class Archivedownload extends AppCompatActivity {
private TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_archivedownload);
textView=findViewById(R.id.textView4);
textView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = getIntent();
String s = textView.getText().toString();
intent.putExtra("position3", s);
setResult(RESULT_OK,intent);
finish();
}
});
}
}

activity_archivedownload.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:background="@drawable/game3"
tools:context=".Archivedownload">
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#DC143C"
android:textSize="60dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="这是档案下载"/>
</RelativeLayout>

设计人员界面

Designintroduce.class

package com.example.myapplication1;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView; public class Designintroduce extends AppCompatActivity {
private TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_designintroduce);
textView=findViewById(R.id.textView5);
textView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = getIntent();
String s = textView.getText().toString();
intent.putExtra("position4", s);
setResult(RESULT_OK,intent);
finish();
}
});
}
}

activity_designintroduce.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
tools:context=".Designintroduce">
<TextView
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#DC143C"
android:textSize="60dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="这是设计人员"/>
</RelativeLayout>

移动应用开发 第5讲 Activity课堂综合练习的更多相关文章

  1. Android开发之漫漫长途 Ⅱ——Activity的显示之Window和View(1)

    该文章是一个系列文章,是本人在Android开发的漫漫长途上的一点感想和记录,我会尽量按照先易后难的顺序进行编写该系列.该系列引用了<Android开发艺术探索>以及<深入理解And ...

  2. Android开发之漫漫长途 Ⅳ——Activity的显示之ViewRootImpl初探

    该文章是一个系列文章,是本人在Android开发的漫漫长途上的一点感想和记录,我会尽量按照先易后难的顺序进行编写该系列.该系列引用了<Android开发艺术探索>以及<深入理解And ...

  3. 第35讲 Activity入门和跳转

    第35讲Activity入门和跳转 1.Activity Activity是用户接口程序.在Android当中,Activity提供可视化的用户界面,一个Android应用通常由多个activity组 ...

  4. android开发中关于继承activity类中方法的调用

    android开发中关于继承activity类中的函数,不能在其他类中调用其方法. MainActivity.java package com.example.testmain; import and ...

  5. Android开发之漫漫长途 Ⅱ——Activity的显示之Window和View(2)

    该文章是一个系列文章,是本人在Android开发的漫漫长途上的一点感想和记录,我会尽量按照先易后难的顺序进行编写该系列.该系列引用了<Android开发艺术探索>以及<深入理解And ...

  6. Android开发——异步任务中Activity销毁时的问题

    0.  前言 在Android开发中经常会发生Activity的销毁重建,比如用户长时间接听一个电话后回到APP.在Android开发--Fragment知识整理(二)中我们提到了使用Fragment ...

  7. Android开发之漫漫长途 Ⅲ——Activity的显示之Window和View(2)

    该文章是一个系列文章,是本人在Android开发的漫漫长途上的一点感想和记录,我会尽量按照先易后难的顺序进行编写该系列.该系列引用了<Android开发艺术探索>以及<深入理解And ...

  8. Android开发艺术1之Activity的生命周期

    作为<Android开发艺术探索>这本书的第一篇博客,我就多说几句.本系列博客旨在对书中相关内容进行解读,简化,提供一个入门到提高的流程.不敢说书评,也不能说教程,只希望对有些人有帮助就好 ...

  9. Android开发艺术2之Activity的启动模式

    Activity是Android的四大组件之一,他的重要性毋庸置疑,对于这么重要的一个组件,我们首先要知道这些都是由系统进行管理和回调的,要理解Activity的启动模式,我们首先来了解一下Andro ...

随机推荐

  1. Android Studio 中的 button 无法使用 background 更改背景颜色

    •解决方案 res/values/themes.xml下的  <style name="Theme.HelloWorld" parent="Theme.Materi ...

  2. Linux标准输入、重定向与参数传递

    Linux标准输入.重定向与参数传递 按惯例,每当运行一个新程序时,所有shell都为其打开3个文件描述符,即标准输入.标准输出以及标准错误.如果不做特殊处理,例如就像简单的命令ls,则这三个描述符都 ...

  3. 生产中常用的du命令

    1. 介绍 du是用来查看文件或目录所占用磁盘空间的大小 du [-abcDhHklmsSx] [-L <符号连接>][-X <文件>][--block-size][--exc ...

  4. [BFS]电子老鼠闯迷宫

    电子老鼠闯迷宫 Description 如下图12×12方格图,找出一条自入口(2,9)到出口(11,8)的最短路径. Input Output Sample Input 12 //迷宫大小 2 9 ...

  5. 翻译:《实用的Python编程》09_01_Packages

    目录| 上一节 (8.3 调试) | 下一节 (9.2 第三方包) 9.1 包 如果编写一个较大的程序,我们并不真的想在顶层将其组织为一个个独立文件的大型集合.本节对包(package)进行介绍. 模 ...

  6. 【笔记】《Redis设计与实现》chapter13 客户端

    服务器为每个客户端建立相应的redis.h/redisClient结构,这个结构保存了客户端当前的状态信息 客户端的套接字描述符 客户端的名字 客户端的标志值 只想客户端正在使用的数据库的指针,以及该 ...

  7. RE.从单链表开始的数据结构生活(bushi

    单链表 单链表中节点的定义 typedef struct LNode{ int data;//数据域 struct LNode *next;//定义一个同类型的指针,指向该节点的后继节点 }LNode ...

  8. 05.ElementUI源码学习:项目发布配置(github pages&npm package)

    0x00.前言 书接上文.项目第一个组件已经封装好,说明文档也已编写好.下面需要将说明文档发布到外网上,以此来展示和推广项目,使用 Github Pages功能实现.同时将组件发布之 npm 上,方便 ...

  9. 06- web兼容性测试与web兼容性测试工具

    web兼容性概述 定义:软件兼容性测试是指检查软件之间能否正确地进行交互和共享信息.随着用户对来自各种类型软件之间共享数据能力和充分利用空间同时执行多个程序能力的要求,测试软件之间能否协作变得越来越重 ...

  10. Python中数据的排序

    目录 列表的排序 sort(key,reverse)方法 sorted(target,key,reverse) 函数 元组tuple的排序 sort(key,reverse)方法 sorted(tar ...