zoukankan      html  css  js  c++  java
  • 20162307 实验四 Android程序设计

    实验四 《Android程序设计》

    北京电子科技学院(BESTI)

    实 验 报 告

    课程:程序设计与数据结构

    班级:1623

    姓名:张韵琪

    学号:20162307

    指导教师:娄佳鹏老师、王志强老师

    实验日期:2017年5月26号

    实验密级:非密级

    实验时间:一周

    必修/选修:必修

    实验名称:Android程序设计

    实验仪器:电脑

    实验目的与要求:

    • 目的:

       学习Android程序设计
      
    • 要求:

        1.没有Linux基础的同学建议先学习《Linux基础入门(新版)》《Vim编辑器》 课程
      
        2.完成实验、撰写实验报告,实验报告以博客方式发表在博客园,注意实验报告重点是运行结果,遇到的问题(工具查找,安装,使用,程序的编辑,调试,运行等)、解决办法(空洞的方法        如“查网络”、“问同学”、“看书”等一律得0分)以及分析(从中可以得到什么启示,有什么收获,教训等)。报告可以参考范飞龙老师的指导
      
        3. 严禁抄袭,有该行为者实验成绩归零,并附加其他惩罚措施。
      

    实验内容、步骤

    • 安装 Android Studio (Mac版)
      - 到官网安装Android Studio 官网地址:https://developer.android.google.cn/studio/index.html
      - 选择 我已阅读并同意上述条款及条件

      - 下载完毕之后,将 Android Studio 拖放到“Applications”文件夹中,然后启动 Android Studio。
      - 选择是否想要导入之前的 Android Studio 设置,然后点击 OK。
      - 之后 Android Studio 设置向导将指导您完成余下的设置,包括下载开发所需的 Android SDK 组件

    • 关于git push问题
      - 先参考此篇博客
      - 再打开终端,具体命令:

        localhost:~ zhangyunqi$ history
        注意:前面序号不要管    
        32    cd AndroidStudioProjects/
        33  ls
        34  cd zhangyunqiapp2(你的AndroidStudio 自己起的名字)
        35  ls
        36  ls -a
        37  git push
        38  ls
        39  cd zhangyunqiapp2
        40  ls
        41  git status
        42  git add .
        43  git commit -m "gradle"
        44  git push
        45  git push --set-upstream origin master
        46  git pull
        47  git branch
        48  git status
        49  git pull
        50   git branch
        51  git branch /?
        52  ls
        53   git status
        54  cd ..
        55  ls
        56  ls
        57  mkdir Tiffany4
        58  cd Tiffany4
        59  ls
        60  git clone http://git.oschina.net/pdds2017/20162307androidapp.git(码云上的链接)
        61  ls
        62  cd 20162307androidapp
        63  ls
        64  cd ..
        65  ls
        66  cd ..
        67  ls
        68  cd zhangyunqiapp2
        69  ls
        70  git clone http://git.oschina.net/pdds2017/20162307androidapp.git
        71  ls
        72  ls -a
        73  rm.git
        74  rm -rf .git
        75  ls
        76  ls -a
        77  rm .gitignore
        78  ls -a
        79  mv *.* 20162307androidapp/
        80  ls
        81   mv build/ 20162307androidapp/
        82  mv gradle 20162307androidapp/
        83  mv gradlew 20162307androidapp/
        84  mv app/ 20162307androidapp/
        85  ls
        86  ls -a
        87  mv .gradle/ 20162307androidapp/
        88  mv .idea/ 20162307androidapp/
        89  ls
        90  cd 20162307androidapp/
        91  ls
        92  git add .
        93  ls
        94  git commit -m "finish android projects"
        95  git push
      

    实验内容1

         Android Studio的安装测试: 参考《Java和Android开发学习指南(第二版)(EPUBIT,Java for Android 2nd)》第二十四章:
        - 安装 Android Studio
        - 完成Hello World, 要求修改res目录中的内容,Hello World后要显示自己的学号,提交代码运行截图和码云Git链接,截图没有学号要扣分
        - 学习Android Studio调试应用程序
    

    实验步骤1

    1.按照娄老师所给的博客,创建a new Android Studio project . 博客链接:http://www.cnblogs.com/rocedu/p/6824965.html
    2.然后 res目录-->layout目录-->activity_main.xml将android:text="Hello World!" 改为android:text="Hello World!20162307"

    实验结果1

    实验内容2

        Activity测试: 参考《Java和Android开发学习指南(第二版)(EPUBIT,Java for Android 2nd)》第二十五章:
        - 构建项目,运行教材相关代码
        -  创建 ThirdActivity, 在ThirdActivity中显示自己的学号,修改代码让MainActivity启动ThirdActivity
        - 提交代码运行截图和码云Git链接,截图要有学号水印,否则会扣分
    

    实验步骤2

    1.app右键--> new-->Activity-->Gallery,选择Empty Activity然后点击next
    2.接下来的界面

    3.点击finish
    4.在MainActivity原有的代码的基础上加上下面的代码

        @Override
            public boolean onCreateOptionsMenu(Menu menu) {
            getMenuInflater().inflate(R.menu.menu_main, menu);
                return true;
            }
    
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                Intent intent = new Intent(this, ThirdActivity.class);
                intent.putExtra("message", "20162307张韵琪实验2");
                startActivity(intent);
                return true;
    
        }
    

    5.将ThirdActivity改为

        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_main, menu);
                return true;
            }
        }
    

    6.在activity_third.xml中添加一段代码:

        <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/textView1"
                />
    

    7.在AndroidManifest.xml添加下面的代码
    <activity

            android:name=".ThirdActivity"
    
            android:label="Third Activity">
    
            <intent-filter>
    
                <action android:name="com.blackay.test.helloworld.ThirdActivity" />
    
                <category android:name="android.intent.category.DEFAULT" />
    
            </intent-filter>
    
        </activity>
    

    实验结果2

    实验内容3

        UI测试: 参考《Java和Android开发学习指南(第二版)(EPUBIT,Java for Android 2nd)》第二十六章:
        - 构建项目,运行教材相关代码
        -  修改代码让Toast消息中显示自己的学号信息
        - 提交代码运行截图和码云Git链接,截图要有学号水印,否则会扣分
    

    实验步骤3

    MainActivity.java代码:

        package com.example.zhangyunqi.zhangyunqiapp;
    
        import android.content.Context;
        import android.support.v7.app.AppCompatActivity;
        import android.os.Bundle;
        import android.app.Activity;
        import android.util.AttributeSet;
        import android.view.Menu;
        import android.view.MenuItem;
        import android.view.View;
        import android.widget.Button;
        import android.widget.Toast;
    
        public class MainActivity extends AppCompatActivity {
    
            @Override
            protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.activity_main);
                Button btnshow1 = (Button) findViewById(R.id.btn1);
                btnshow1.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Toast toast = Toast.makeText(MainActivity.this, "20162307张韵琪实验3", Toast.LENGTH_LONG);
                        toast.show();
    
                    }
                });
            }
    
        
        }       
    

    activity_main.xml代码:

        <?xml version="1.0" encoding="utf-8"?>
        <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:paddingBottom="10dp"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"
            android:paddingTop="10dp"
            tools:context=".MainActivity" >
            <TextView
                android:id="@+id/textView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="first_screen" />
            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="20162307张韵琪实验3"
                android:id="@+id/btn1"
                android:layout_alignParentTop="true"
                android:layout_marginTop="31dp"
                android:layout_alignParentRight="true"
                android:layout_alignParentEnd="true"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true" />
        </RelativeLayout>
    

    实验结果3

    实验内容4

        布局测试: 参考《Java和Android开发学习指南(第二版)(EPUBIT,Java for Android 2nd)》第二十七章:
        - 构建项目,运行教材相关代码
        -  修改布局让P290页的界面与教材不同
        - 提交代码运行截图和码云Git链接,截图要有学号水印,否则会扣分
    

    实验步骤4

    activity_main.xml代码:

        <?xml version="1.0" encoding="utf-8"?>
        <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:paddingBottom="10dp"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"
            android:paddingTop="10dp"
            tools:context=".MainActivity" >
            <TextView
                android:id="@+id/textView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="first_screen" />
            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="20162307张韵琪实验4"
                android:id="@+id/btn1"
                android:layout_alignParentTop="true"
                android:layout_marginTop="31dp"
                android:layout_alignParentRight="true"
                android:layout_alignParentEnd="true"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true" />
            <FrameLayout
            android:layout_width="368dp"
            android:layout_height="495dp"
            android:orientation="horizontal"
            tools:layout_editor_absoluteX="11dp"
            tools:layout_editor_absoluteY="16dp">
    
            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="160dp"
                android:layout_marginTop="150dp"
                android:text="20162307实验4" />
        
            <ImageButton
                android:id="@+id/imageButton"
                android:layout_width="131dp"
               android:layout_height="69dp"
                android:layout_marginLeft="160dp"
                android:layout_marginTop="140dp"
                android:alpha="0.4"
                android:src="@android:drawable/btn_star_big_on" />
        </FrameLayout>
        </RelativeLayout>
    

    实验结果4:

    实验内容5

        事件处理测试: 参考《Java和Android开发学习指南(第二版)(EPUBIT,Java for Android 2nd)》第二十八章:
        - 构建项目,运行教材相关代码
        - 提交代码运行截图和码云Git链接,截图要有学号水印,否则会扣分
    

    实验步骤4

    activity_main.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:paddingBottom="40dp"
            android:paddingLeft="40dp"
            android:paddingRight="40dp"
            tools:context=".MainActivity">
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="20162307实验5"></TextView>
    
            <AnalogClock
                android:id="@+id/analogClock1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="200dp"
                android:onClick="changeColor" />
        </RelativeLayout>
    

    MainActivity.java代码:

        package com.example.zhangyunqi.zhangyunqiapp;
    
        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};
    
            @Override
            protected 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++]);
            }
        }
    

    实验结果5

    统计自己的PSP(Personal Software Process)时间

    步骤 耗时 百分比
    需求分析 60min 14.0%
    代码实现 170min 39.5%
    测试 150min 34.9%
    分析总结 50min 11.6%

    实验总结与体会

    觉得AndroidStudio是一个新的体验,和之前学习的不大相同,在AndroidStudio中git是最麻烦的,是最难弄的,所以我把怎么弄git写在我的博客里。

    此次实验链接

  • 相关阅读:
    golang 使用错误总结
    golang 跨平台交叉编译
    golang redis 第三方包
    golang 浮点型 与其他数值类型计算
    golang 更友好的格式化输出
    golang 指定长度 随机数 & 随机字符串
    go语言中int和byte转换方式
    基础知识
    golang bytes 包 详解
    golang 解析 ini 文件 中文文档
  • 原文地址:https://www.cnblogs.com/Tiffany23/p/6907105.html
Copyright © 2011-2022 走看看