zoukankan      html  css  js  c++  java
  • 2018-2019-2 20175214 实验四《Android程序设计》实验报告

    实验四《Android程序设计》实验报告

    一、前期准备

      1. 安装Android Studio
      • 参考http://www.cnblogs.com/rocedu/p/6371315.html#SECANDROID,安装 Android Stuidio

      • 安装完成后配置和启动模拟器。

      • 具体过程略。

      1. 翻阅参考《Java和Android开发学习指南(第二版)(EPUBIT,Java for Android 2nd)》;
      • 由于老师给的链接失效,自行上网下载了一个pdf。

    二、实验内容

    • 任务一 Android Stuidio的安装测试:
      • 参考《Java和Android开发学习指南(第二版)(EPUBIT,Java for Android 2nd)》第二十四章:
      • 参考http://www.cnblogs.com/rocedu/p/6371315.html#SECANDROID,安装 Android Stuidio
      • 完成Hello World, 要求修改res目录中的内容,Hello World后要显示自己的学号,自己学号前后一名同学的学号,提交代码运行截图和码云Git链接,截图没有学号要扣分
      • 学习Android Stuidio调试应用程序
    • 任务二 Activity测试:
      • 参考《Java和Android开发学习指南(第二版)(EPUBIT,Java for Android 2nd)》第二十五章:
      • 构建项目,运行教材相关代码
      • 创建 ThirdActivity, 在ThirdActivity中显示自己的学号,修改代码让MainActivity启动ThirdActivity
      • 提交代码运行截图和码云Git链接,截图要有学号水印,否则会扣分
    • 任务三 UI测试:
      • 参考《Java和Android开发学习指南(第二版)(EPUBIT,Java for Android 2nd)》第二十六章:
      • 构建项目,运行教材相关代码
      • 修改代码让Toast消息中显示自己的学号信息
      • 提交代码运行截图和码云Git链接,截图要有学号水印,否则会扣分
    • 任务四 布局测试:
      • 参考《Java和Android开发学习指南(第二版)(EPUBIT,Java for Android 2nd)》第二十七章:
      • 构建项目,运行教材相关代码
      • 修改布局让P290页的界面与教材不同
      • 提交代码运行截图和码云Git链接,截图要有学号水印,否则会扣分
    • 任务五 事件处理测试:
      • 参考《Java和Android开发学习指南(第二版)(EPUBIT,Java for Android 2nd)》第二十八章:
      • 构建项目,运行教材相关代码
      • 提交代码运行截图和码云Git链接,截图要有学号水印,否则会扣分

    三、实验步骤

    • 任务一 Android Stuidio的安装测试

      • 由于HelloWorld是自带的,所以创建项目后对布局文件进行简单修改即可;
      • 布局文件代码:
      <?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">
       <TextView
           android: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!20175214 20175213 20175215" />
      
      </android.support.constraint.ConstraintLayout>
      
      • 测试结果截图:
    • 任务二 Activity测试

      • 创建项目,新建题中要求的ThirdActivity;

      • 参考《Java和Android开发学习指南(第二版)》键入代码;

      • MainActivity.java

      package com.example.helloworld;
      
      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 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 onTouch(View arg0, MotionEvent event) {
            Intent intent = new Intent(this, ThirdActivity.class);
            intent.putExtra("message", "ThirdActivity 20175214");
            startActivity(intent);
            return true;
        }
      }
      
      
      • ThirdActivity.java
      package com.example.helloworld;
      

    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);
    }
    }

       - `activity_main.xml`
    



       - `activity_third.xml`
    



       - 测试结果截图:
    ![](https://img2018.cnblogs.com/blog/1592121/201905/1592121-20190516210936831-530628037.png)
    
    ![](https://img2018.cnblogs.com/blog/1592121/201905/1592121-20190516210731891-2102460065.png)
    
    - 任务三 UI测试
       - 创建项目;
       - 参考《Java和Android开发学习指南(第二版)》键入代码;
       - `MainActivity.java`
        ```
    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,"20175214 林郅聪",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">
     <TextView
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:text="Hello!My name is ↓↓↓"
         app:layout_constraintBottom_toBottomOf="parent"
         app:layout_constraintLeft_toLeftOf="parent"
         app:layout_constraintRight_toRightOf="parent"
         app:layout_constraintTop_toTopOf="parent" />
    </android.support.constraint.ConstraintLayout>
    
    • 测试结果截图

    • 任务四 布局测试

      • 创建项目;
      • 参考《Java和Android开发学习指南(第二版)》键入代码;
      • 修改代码以改变布局;
      • MainActivity.java

    package com.example.ui;
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.relative_layout);
    }
    }

    - `relative_layout.xml`
    
    
    <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"
    android:paddingLeft="2dp"
    android:paddingRight="2dp">
    <Button
        android:id="@+id/cancelButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="20175214"
        android:layout_marginTop="70dp"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true" />
    <Button
        android:id="@+id/saveButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="林郅聪"
        android:layout_below="@+id/cancelButton"
        android:layout_alignLeft="@+id/cancelButton"
        android:layout_alignStart="@+id/cancelButton"
        android:layout_marginTop="23dp" />
        <ImageView
            android:layout_width="150dp"
            android:layout_height="150dp"
            android:layout_marginTop="45dp"
            android:padding="4dp"
            android:src="@android:drawable/ic_btn_speak_now" />
    


  • 相关阅读:
    famous javascript library.
    54陈上有一些技术文章
    codeforces 612A The Text Splitting(扩展欧几里得)
    UVA 11235 Frequent values
    codeforces 604A Uncowed Forces
    nyoj 138 找球号(二)
    codeforces 592A PawnChess
    cidefirces Educational Codeforces Round 2 A. Extract Numbers
    cidefirces Educational Codeforces Round 2 B Queries about less or equal elements
    codeforces Educational Codeforces Round 2 C Make Palindrome
  • 原文地址:https://www.cnblogs.com/fzlzc/p/10878065.html
Copyright © 2011-2022 走看看