20175208 张家华 实验四《Android开发基础》实验报告
一、实验报告封面
- 课程:Java程序设计 班级:1752班 姓名:张家华 学号:20175208
- 指导教师:娄嘉鹏 实验日期:2019年5月16日
- 实验时间:--- 实验序号:实验四
实验名称:Android开发基础
- 实验要求:
- 没有Linux基础的同学建议先学习《Linux基础入门(新版)》《Vim编辑器》 课程
- 完成实验、撰写实验报告,实验报告以博客方式发表在博客园,注意实验报告重点是运行结果,遇到的问题(工具查找,安装,使用,程序的编辑,调试,运行等)、解决办法(空洞的方法如“查网络”、“问同学”、“看书”等一律得0分)以及分析(从中可以得到什么启示,有什么收获,教训等)。报告可以参考范飞龙老师的指导
- 严禁抄袭,有该行为者实验成绩归零,并附加其他惩罚措施。
二、实验内容及步骤
1.Android Stuidio的安装测试
- 要求:
- 参考http://www.cnblogs.com/rocedu/p/6371315.html#SECANDROID,安装 Android Stuidio
- 完成Hello World, 要求修改res目录中的内容,Hello World后要显示自己的学号,自己学号前后一名同学的学号,提交代码运行截图和码云Git链接,截图没有学号要扣分
- 学习Android Stuidio调试应用程序
安装配置过程
先在官网上下载对应版本的Android studio,然后基本就是一步接着一步正常安装就可以了。
打开后如图所示:
实验代码:
<?xml version="1.0" encoding="utf-8"?><android.support.constraint.ConstraintLayoutxmlns: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=".MainActivity"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginEnd="80dp"android:layout_marginRight="80dp"android:text="Hello World!20175214 20175213 20175215"app:layout_constraintBottom_toBottomOf="parent"app:layout_constraintEnd_toEndOf="parent"app:layout_constraintLeft_toLeftOf="parent"app:layout_constraintRight_toRightOf="parent"app:layout_constraintTop_toTopOf="parent"tools:text="Hello World!20175208 20175207 20175209" /></android.support.constraint.ConstraintLayout>
实验运行结果:
2.Activity测试
- 要求:
- 构建项目,运行教材相关代码
- 创建 ThirdActivity, 在ThirdActivity中显示自己的学号,修改代码让MainActivity启动ThirdActivity
- 提交代码运行截图和码云Git链接,截图要有学号水印,否则会扣分
onCreat函数
- 调用onCreat函数,创建活动开始
onTouch事件
- 负责设置触碰事件,在本程序中负责第二个活动
ThirdActivity
的调用,可利用Intent类创建对象,再用startActivity
实现跳转
TextView类
- 在两个活动中,都包括TextView类,触发主活动中的TextView,会启动第二个活动,并将消息传给后者
MainActivity代码:
package com.example.helloword;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.TextView;
public class MainActivity extends Activity implementsOnTouchListener {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);TextView tv = (TextView) findViewById(R.id.textView1);tv.setOnTouchListener(this);}@Overridepublic boolean onTouch(View arg0, MotionEvent event) {Intent intent = new Intent(this, ThirdActivity.class);intent.putExtra("message", "ThirdActivity 20175208");startActivity(intent);return true;}
}<RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"android:paddingBottom="10dp"android:paddingLeft="10dp"android:paddingRight="10dp"android:paddingTop="10dp"tools:context=".ThirdActivity" ><TextViewandroid:id="@+id/textView1"android:layout_width="wrap_content"android:layout_height="wrap_content" /></RelativeLayout>
package com.example.helloword;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.widget.TextView;
public class ThirdActivity extends Activity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_third);Intent intent = getIntent();String message = intent.getStringExtra("message");((TextView) findViewById(R.id.textView1)).setText(message);}
}<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"tools:context=".MainActivity"><TextViewandroid:id="@+id/textView1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="FirstActivity 20175208" />
</RelativeLayout>
实验运行结果:
3.UI测试
- 要求:
- 修改代码让Toast消息中显示自己的学号信息
- 提交代码运行截图和码云Git链接,截图要有学号水印,否则会扣分
MainActivity代码
package com.example.toast;
import android.content.DialogInterface;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);Toast.makeText(this,"20175208 张家华",Toast.LENGTH_LONG).show();
}
}
activity_main.xml
<?xml version="1.0" encoding="UTF-8"?>
<android.support.constraint.ConstraintLayout 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=".MainActivity"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"app:layout_constraintBottom_toBottomOf="parent"app:layout_constraintLeft_toLeftOf="parent"app:layout_constraintRight_toRightOf="parent"app:layout_constraintTop_toTopOf="parent" /><Buttonandroid:id="@+id/btn1"android:layout_width="wrap_content"android:layout_height="fill_parent"android:text="Hello!" />
</android.support.constraint.ConstraintLayout>
实验运行结果:
4.布局测试
- 要求
- 修改布局让P290页的界面与教材不同
- 提交代码运行截图和码云Git链接,截图要有学号水印,否则会扣分
MainActivity:
package com.example.myapplication;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;public class MainActivity extends AppCompatActivity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);}
}
activity_main.xml:
<RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"android:paddingLeft="2dp"android:paddingRight="2dp"><Buttonandroid:id="@+id/cancelButton"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="20175208"android:layout_marginTop="70dp"android:layout_alignParentTop="true"android:layout_centerHorizontal="true" /><Buttonandroid:id="@+id/saveButton"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="zjh"android:layout_below="@+id/cancelButton"android:layout_alignLeft="@+id/cancelButton"android:layout_alignStart="@+id/cancelButton"android:layout_marginTop="23dp" /><ImageViewandroid:layout_width="150dp"android:layout_height="150dp"android:layout_marginTop="45dp"android:padding="4dp"android:src="@android:drawable/ic_btn_speak_now" /><LinearLayoutandroid:id="@+id/filter_button_container"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_alignParentBottom="true"android:gravity="center|bottom"android:background="@android:color/white"android:orientation="horizontal" ><Buttonandroid:id="@+id/filterButton"android:layout_width="wrap_content"android:layout_height="fill_parent"android:text="Filter" /><Buttonandroid:id="@+id/shareButton"android:layout_width="wrap_content"android:layout_height="fill_parent"android:text="Share" /><Buttonandroid:id="@+id/deleteButton"android:layout_width="wrap_content"android:layout_height="fill_parent"android:text="Delete" /></LinearLayout>
</RelativeLayout>
实验运行结果:
5.事件处理测试
- 要求:运行教材本章相关代码并截图
监听器
- Android是基于事件的。使用活动中的一个视图进行的用户交互,可能会触发一个事件,包括点击、长按、触碰和按键等等
- 要让程序响应某一个事件,需要为该事件编写一个监听器。也就是要实现嵌入在android.view.View类中的一个接口。比如OnClickListener接口的onClick()方法
MainActivity
package com.example.myapplication;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.AnalogClock;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.AnalogClock;
public class MainActivity extends Activity {int counter = 0;int[] colors = { Color.BLACK, Color.BLUE, Color.CYAN,Color.DKGRAY, Color.GRAY, Color.GREEN, Color.LTGRAY,Color.MAGENTA, Color.RED, Color.WHITE, Color.YELLOW };@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);}public void changeColor(View view) {if (counter == colors.length) {counter = 0;}view.setBackgroundColor(colors[counter++]);}
}
activity_main.xml:
<?xml version="1.0" encoding="utf-8"?><RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"tools:context=".MainActivity"><AnalogClockandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentTop="true"android:layout_centerHorizontal="true"android:layout_marginTop="90dp"android:id="@+id/analogClock1"android:onClick="changeColor" /><TextViewandroid:layout_width="match_parent"android:layout_height="match_parent"android:text="20175208zjh"android:layout_marginLeft="70dp"android:layout_marginTop="300dp"android:textSize="38dp"android:textColor="#bbbb00"/>
</RelativeLayout>
实验运行结果:
三、码云连接:
https://gitee.com/zhangjiahua20175208/codes/c0v8ahkg7zl4nt2m1j39f28
https://gitee.com/zhangjiahua20175208/codes
四、实验心得体会:
这次实验的内容Android开发是我一直都没有接触过的领域,在实验的过程中遇到了很多问题,在这个过程中,我参考了一些博客,也跟同学们交流讨论了,解决了很多问题。通过这次实验,我在Android开发上学习了很多,也初步接触了开发方面的知识的运用,并能够运行虚拟手机,对Android开发基本功能的运用了解的更深入。
转载于:https://www.cnblogs.com/kaoru/p/10880685.html
20175208 张家华 实验四《Android开发基础》实验报告相关推荐
- 20155202 实验四 Android开发基础
20155202 实验四 Android开发基础 实验内容 1.基于Android Studio开发简单的Android应用并部署测试; 2.了解Android.组件.布局管理器的使用: 3.掌握An ...
- 实验四android开发基础
实验四android开发基础 提交点一 Android Stuidio的安装测试: 参考<Java和Android开发学习指南(第二版)(EPUBIT,Java for Android 2nd) ...
- 20175201张驰 实验四 Android 开发
4-1:[Android Studio安装]安装过程中出现的错误:参考https://blog.csdn.net/weixin_38277423/article/details/80254483 1. ...
- 20175208 张家华 MyOD
一.实现目的: 编写MyOD.java 用java MyOD XXX实现Linux下od -tx -tc XXX的功能 二.功能简介 1.Linux下的od功能是将指定文件内容以八进制.十进制.十六进 ...
- 20175208 张家华 MyCP
一.内容 编写MyCP.java 实现类似Linux下cp XXX1 XXX2的功能,要求MyCP支持两个参数: java MyCP -tx XXX1.txt XXX2.bin 用来把文本文件(内容为 ...
- 20175208 张家华 MySort
MySort 注意:研究sort的其他功能,要能改的动代码,需要答辩 模拟实现Linux下Sort -t : -k 2的功能. 要有伪代码,产品代码,测试代码(注意测试用例的设计) 参考 Sort的实 ...
- 20145122《Android开发基础》实验四实验报告
实验名称 Android开发基础 实验内容 1.Windows环境下Android Studio 2.能够运行安卓AVD模拟器 3.使用安卓虚拟手机显示HelloWorld以及自己的学号 统计的PSP ...
- 2018-2019-2-20175225 实验四《Android开发基础》实验报告
一.实验报告封面 课程:Java程序设计 班级:1752班 姓名:张元瑞 学号:20175225 指导教师:娄嘉鹏 实验日期:2019年5月14日 实验时间:13:45 - 21:00 实验序号:实验 ...
- 20175308 2018-2019-2 实验四 《Android开发基础》实验报告
20175308 2018-2019-2 实验四 <Android开发基础>实验报告 实验要求 参考 Android开发简易教程 完成云班课中的检查点,也可以先完成实验报告,直接提交.注意 ...
最新文章
- IBM X3650 M2 BR10i卡的阵列配置方法
- Spring MVC集成Tiles使用方法
- 把二叉搜索树转换为累加树—leetcode538
- 简易贪吃蛇小游戏java版_用GUI实现java版贪吃蛇小游戏
- 显示播客信息-bloginfo() 函数
- 实验2-4-2 生成3的乘方表 (C语言)
- Python 之 函数进阶
- 一道不知道哪里来的容斥题
- 【HUD2072】单词数(字典树-统计一句话中不同单词的个数)
- Arduino GPS 车速表(Arduino流体力学燃油效率计)(更新:2022.7.3)
- HTML5游戏引擎(十七)-egret引擎实战——踩格子游戏
- java开发 微信商家转账到零钱,发起商家转账API,微信支付
- 项目团队管理:有效管理团队的八个方法
- 转载一篇c语言深度文章 《一个“蝇量级” C 语言协程库》
- html 中数字一直往上加的动态效果,CSS动画:数字增量效果
- excel怎么批量插行_条码打印软件如何批量打印条形码图片(一)
- 成都理工大学计算机考研经历,09计算机考研的小小体会~
- zookeeper的watcher机制
- 分享几个Wordpress模板下载网站
- 基础编程题(1~5)
热门文章
- 用计算机控制单片机的程序编写,单片机程序编写步骤
- VS调试C++程序,提示无法启动程序,“xx.exe”。系统找不到指定文件的解决办法
- DO=MOSI DI=MISO
- H5唤起APP进行分享的尝试
- 基于FPGA/MATLAB的偏移正交相移键控的仿真实现
- python colorbar字体大小_如何更改colorbar上基数和指数的字体大小?
- 笔记|统计学习方法:感知机模型
- 基于java的滑雪场学具租赁管理系统计算机毕业设计源码+系统+lw文档+mysql数据库+调试部署
- fm24c16c语言程序,铁电存储器FM24C16的页面写和任意字节读汇编程序
- Android 实现顶层窗口、悬浮窗口