移动应用开发 第5讲 Activity课堂综合练习
作业总要求
使用附件“素材”压缩包中的素材完成下列任务:
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课堂综合练习的更多相关文章
- Android开发之漫漫长途 Ⅱ——Activity的显示之Window和View(1)
该文章是一个系列文章,是本人在Android开发的漫漫长途上的一点感想和记录,我会尽量按照先易后难的顺序进行编写该系列.该系列引用了<Android开发艺术探索>以及<深入理解And ...
- Android开发之漫漫长途 Ⅳ——Activity的显示之ViewRootImpl初探
该文章是一个系列文章,是本人在Android开发的漫漫长途上的一点感想和记录,我会尽量按照先易后难的顺序进行编写该系列.该系列引用了<Android开发艺术探索>以及<深入理解And ...
- 第35讲 Activity入门和跳转
第35讲Activity入门和跳转 1.Activity Activity是用户接口程序.在Android当中,Activity提供可视化的用户界面,一个Android应用通常由多个activity组 ...
- android开发中关于继承activity类中方法的调用
android开发中关于继承activity类中的函数,不能在其他类中调用其方法. MainActivity.java package com.example.testmain; import and ...
- Android开发之漫漫长途 Ⅱ——Activity的显示之Window和View(2)
该文章是一个系列文章,是本人在Android开发的漫漫长途上的一点感想和记录,我会尽量按照先易后难的顺序进行编写该系列.该系列引用了<Android开发艺术探索>以及<深入理解And ...
- Android开发——异步任务中Activity销毁时的问题
0. 前言 在Android开发中经常会发生Activity的销毁重建,比如用户长时间接听一个电话后回到APP.在Android开发--Fragment知识整理(二)中我们提到了使用Fragment ...
- Android开发之漫漫长途 Ⅲ——Activity的显示之Window和View(2)
该文章是一个系列文章,是本人在Android开发的漫漫长途上的一点感想和记录,我会尽量按照先易后难的顺序进行编写该系列.该系列引用了<Android开发艺术探索>以及<深入理解And ...
- Android开发艺术1之Activity的生命周期
作为<Android开发艺术探索>这本书的第一篇博客,我就多说几句.本系列博客旨在对书中相关内容进行解读,简化,提供一个入门到提高的流程.不敢说书评,也不能说教程,只希望对有些人有帮助就好 ...
- Android开发艺术2之Activity的启动模式
Activity是Android的四大组件之一,他的重要性毋庸置疑,对于这么重要的一个组件,我们首先要知道这些都是由系统进行管理和回调的,要理解Activity的启动模式,我们首先来了解一下Andro ...
随机推荐
- Nginx记录用户请求Header到access log
为了统计和其它用途,经常有人需要自定义Nginx日志,把http请求中的某个字段记录到日志中,刚好在看lua+nginx的文章,第一想到的是用lua赋值来做,但是想想有点小恶心,于是Google了一番 ...
- ClickHouse性能优化?试试物化视图
一.前言 ClickHouse是一个用于联机分析(OLAP)的列式数据库管理系统(DBMS):目前我们使用CH作为实时数仓用于统计分析,在做性能优化的时候使用了 物化视图 这一特性作为优化手段,本文主 ...
- Node.js 包管理器 NPM 讲解
包管理器又称软件包管理系统,它是在电脑中自动安装.配制.卸载和升级软件包的工具组合,在各种系统软件和应用软件的安装管理中均有广泛应用.对于我们业务开发也很受益,相同的东西不必重复去造轮子. 每个工具或 ...
- ionic3+angular 倒计时效果
// 声明变量 applicationInterval: any; // 定时器 nextBtnText: String; nextBtnBool: Boolean; // 使用定时器,每秒执行一次 ...
- @babel/preset-env使用polyfill遇到的坑
场景还原 最近将一个项目由babel@6升级到babel@7,升级后最重要的两个包: @babel/preset-env: 提供代码的转换和API的polyfill的能力 @babel/plugin- ...
- Day12_62_线程的生命周期
线程的生命周期 要实现多线程,必须在主线程中创建新的线程对象. 任何线程一般都具有五种状态,即创建,就绪,运行,阻塞,终止(消亡) 新建状态:在程序中创建了一个新的线程对象后,新的线程对象便处于新建状 ...
- 869. Reordered Power of 2
Starting with a positive integer N, we reorder the digits in any order (including the original order ...
- Spring Security极简入门三部曲(中篇)
目录 Spring Security极简入门三部曲(中篇) 验证流程 Authentication接口 过滤器链 AuthenticationProvider接口: demo时刻 代码讲解 小结 Sp ...
- PE文件附加数据感染之Worm.Win32.Agent.ayd病毒分析
一.基本信息 样本名称:1q8JRgwDeGMofs.exe 病毒名称:Worm.Win32.Agent.ayd 文件大小:165384 字节 文件MD5:7EF5D0028997CB7DD3484A ...
- LA3403 天平难题
题意: 给出房间的宽度r和每个吊坠的重量wi,设计一个尽量宽但宽度不能超过房间宽度的天平,挂着所有挂坠,每个天平的一段要么挂这一个吊坠,要么挂着另一个天平,每个天平的总长度是1,细节我给出题 ...