作业总要求
使用附件“素材”压缩包中的素材完成下列任务:
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课堂综合练习全部内容,希望文章能够帮你解决移动应用开发 第5讲 Activity课堂综合练习所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)