20155215宣言 实验四 Andoid开发基础实验报告

20155215宣言 实验四 Andoid开发基础实验报告

实验要求

1.没有Linux基础的同学建议先学习《Linux基础入门(新版)》《Vim编辑器》 课程;

2.完成实验、撰写实验报告,实验报告模板见QQ群,注意实验报告重点是运行结果,遇到的问题(工具查找,安装,使用,程序的编辑,调试,运行等)、解决办法(空洞的方法如“查网络”、“问同学”、“看书”等一律得0分)以及分析(从中可以得到什么启示,有什么收获,教训等);

3.实验报告中统计自己的PSP(Personal Software Process)时间:

步骤 耗时 百分比
需求分析
设计
代码实现
测试
分析总结

实验内容

1.Android Stuidio的安装测试:

参考《Java和Android开发学习指南(第二版)(EPUBIT,Java for Android 2nd)》第二十四章:

  • 安装 Android Stuidio
  • 完成Hello World, 要求修改res目录中的内容,Hello World后要显示自己的学号,提交代码运行截图和码云Git链接,截图没有学号要扣分
  • 学习Android Stuidio调试应用程序

Android Studio 是 Android 的官方 IDE。它是专为 Android 而打造,可以加快您的开发速度,帮助您为每款 Android 设备构建最优应用。

它提供专为 Android 开发者量身定制的工具,其中包括丰富的代码编辑、调试、测试和性能分析工具。

安装地址:
https://developer.android.google.cn/studio/install.html

《Java和Android开发学习指南(第二版)(EPUBIT,Java for Android 2nd)》第二十四章中的安装地址是无效的,然后我是参考老师给出的Android开发简易教程进行的安装。

我修改了res/layout/activity_main.xmlz中的内容,使他能够输出我的学号姓名,代码如下:

<?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="cn.edu.besti.is.xy.helloworld.MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World,20155215!"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</android.support.constraint.ConstraintLayout>

2.Activity测试:

参考《Java和Android开发学习指南(第二版)(EPUBIT,Java for Android 2nd)》第二十五章:

  • 构建项目,运行教材相关代码
  • 创建 ThirdActivity, 在ThirdActivity中显示自己的学号,修改代码让MainActivity启动ThirdActivity
  • 提交代码运行截图和码云Git链接,截图要有学号水印,否则会扣分

《Java和Android开发学习指南(第二版)(EPUBIT,Java for Android 2nd)》第二十五章中主要讲的是Android编程中最重要的组件类型之一,活动。
启动一个活动就意味着显示一个窗口,主活动就意味着创建的第一个窗口。
这次的实验要求我们“创建 ThirdActivity, 在ThirdActivity中显示自己的学号,修改代码让MainActivity启动ThirdActivity”,下面是我创建的 MainActivity:

package cn.edu.besti.is.xy.thirdactivity;

/**
 * Created by XY on 2017/5/18.
 */
//import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
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 implements
        OnTouchListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        TextView tv = (TextView) findViewById(R.id.textView1);
        tv.setOnTouchListener(this);
    }
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it
// is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }
    @Override
    public boolean onTouch(View arg0, MotionEvent event) {
        Intent intent = new Intent(this, ThirdActivity.class);
        intent.putExtra("message", "20155215宣言");
        startActivity(intent);
        return true;
    }
}

ThirdActivity则如下所示:

package cn.edu.besti.is.xy.thirdactivity;

/**
 * Created by XY on 2017/5/18.
 */

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 {
    @Override
    protected 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);
    }
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_third, menu);
        return true;
    }
}

刚开始的时候我的虚拟器运行显示错误:

后来我比对他们已经完成的人的代码,修改了很久之后终于有了结果:

3.UI测试:

参考《Java和Android开发学习指南(第二版)(EPUBIT,Java for Android 2nd)》第二十六章:

  • 构建项目,运行教材相关代码
  • 修改代码让Toast消息中显示自己的学号信息
  • 提交代码运行截图和码云Git链接,截图要有学号水印,否则会扣分

4.布局测试:

参考《Java和Android开发学习指南(第二版)(EPUBIT,Java for Android 2nd)》第二十七章:

  • 构建项目,运行教材相关代码
  • 修改布局让P290页的界面与教材不同
  • 提交代码运行截图和码云Git链接,截图要有学号水印,否则会扣分

5.事件处理测试:

参考《Java和Android开发学习指南(第二版)(EPUBIT,Java for Android 2nd)》第二十八章:

  • 构建项目,运行教材相关代码
  • 提交代码运行截图和码云Git链接,截图要有学号水印,否则会扣分

实验感想

这次的实验感觉难度很大,我花费了大量的时间来完成。但是第一次自己设计安卓应用也觉得确实很有成就感,希望自己可以继续努力学习编程的知识。

PSP(Personal Software Process)时间

步骤 耗时 百分比
需求分析 20min 6.7%
设计 30min 10%
代码实现 200min 66.7%
测试 20min 6.7%
分析总结 30min 10%
posted @ 2017-05-20 15:35  xuanyan  阅读(187)  评论(0编辑  收藏  举报