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

    2018-2019-2 20175204 张湲祯 实验四《Android程序设计》实验报告


    实验四Android程序设计

    一.实验内容:

    1.Android程序设计-1

    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调试应用程序

    2.Android程序设计-2

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

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

    3.Android程序设计-3

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

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

    4.Android程序设计-4

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

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

    5.Android程序设计-5

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

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

    二.实验步骤

    1.Android Stuidio的安装测试

    1.参考http://www.cnblogs.com/rocedu/p/6371315.html#SECANDROID,安装 Android Stuidio
    2.安装完成运行后显示缺少SDK,需要下载。
    3.点击下载后需要配置HTTP代理,此步骤一直重复,故在网上搜索后解决问题。(https://blog.csdn.net/u010164190/article/details/53168905)
    4.在根据教程设置后可以下载,完成安装SDK

    5.根据参考步骤新建项目,启动并设置虚拟机。


    6.修改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:id="@+id/textView"
            android:layout_width="wrap_content"
            android:layout_height="15dp"
            android:text="Hello World!20175204 张湲祯20175203马羽达"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toTopOf="parent" />
    
    </android.support.constraint.ConstraintLayout>
    


    7.编译运行app。


    2.Activity测试

    1.新建ThirdActivity ,点击file->New->Activity->点empty activity建立ThirdActivity
    按照要求在activity_third.xml中修改text信息

    <?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=".ThirdActivity">
        <TextView
            android:layout_width="144dp"
            android:layout_height="26dp"
            android:text="20175204张湲祯"
            tools:ignore="MissingConstraints"
            tools:layout_editor_absoluteX="109dp"
            tools:layout_editor_absoluteY="242dp" />
    </android.support.constraint.ConstraintLayout>
    

    3.进到MainActivity.java中修改代码为:

    package com.example.helloworld;
    
    import android.content.Intent;
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.view.MotionEvent;
    import android.view.View;
    
    public class MainActivity extends AppCompatActivity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            Intent intent = new Intent(this,ThirdActivity.class);
            startActivity(intent);
        }
        }
    

    4.运行结果.


    3.UI测试

    1.在MainActivity.java中修改代码

    package com.example.helloworld;
    
    import android.content.Intent;
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.view.MotionEvent;
    import android.view.View;
    import android.widget.Toast;
    
    public class MainActivity extends AppCompatActivity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            Intent intent = new Intent(this,ThirdActivity.class);
            startActivity(intent);
    
            Toast toast = Toast.makeText(MainActivity.this, "2 0 1 7 5 2 0 4 张 湲 祯", Toast.LENGTH_LONG); toast.show();
        }
        }
    

    2.运行结果


    4.布局测试

    1.在activity_third.xml中点击design,切换到布局设计模式。
    2.根据右侧工具栏,可以调整字体颜色,背景颜色,图片等等功能。
    3.调整后发现txt中的代码发生改变。

    <?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=".ThirdActivity">
    
        <TextView
            android:id="@+id/textView2"
            android:layout_width="144dp"
            android:layout_height="169dp"
            android:layout_marginStart="8dp"
            android:layout_marginLeft="8dp"
            android:layout_marginTop="8dp"
            android:layout_marginEnd="8dp"
            android:layout_marginRight="8dp"
            android:layout_marginBottom="8dp"
            android:background="#FFEB3B"
            android:drawableStart="@android:drawable/btn_star_big_on"
            android:drawableTop="@color/colorPrimary"
            android:drawableEnd="@android:drawable/btn_star_big_on"
            android:text="20175204张湲祯"
            android:textColorHighlight="#9C27B0"
            android:textColorLink="#9C27B0"
            android:textSize="18sp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.498"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintVertical_bias="0.452"
            tools:ignore="MissingConstraints" />
    
        <android.support.constraint.Guideline
            android:id="@+id/guideline"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            app:layout_constraintGuide_end="470dp" />
    
        <android.support.constraint.Group
            android:id="@+id/group"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:layout_constraintBottom_toTopOf="parent"
            app:layout_constraintEnd_toStartOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />
    </android.support.constraint.ConstraintLayout>
    


    5.事件处理测试

    1.根据要求修改MainActivity.java中的代码

    package com.example.helloworld;
    
    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;
    
    import com.example.helloworld.R;
    
    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);
        }
        @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;
        }
        public void changeColor(View view) {
            if (counter == colors.length) {
                counter = 0;
            }
            view.setBackgroundColor(colors[counter++]);
        }
    }
    

    2.修改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="10dp"
        android:paddingLeft="10dp"
        android:paddingRight="10dp"
        android:paddingTop="10dp"
        tools:context=".MainActivity">
        <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="90dp"
            android:onClick="changeColor"
            />
    </RelativeLayout>
    

    3.运行结果


    三.在实验中遇到的问题。

    问题1:在进行第一个任务时,运行app时,显示Android安装APK出现DELETE_FAILED_INTERNAL_ERROR,Error while Installing APKs。
    解决方案:根据网上搜索(https://blog.csdn.net/xjj19920608/article/details/70340111)发现与我问题不同。在重新建立一个虚拟机后就可以执行。
    

    四.实验体会

       在本次实验中学习了Android程序开发基础,感觉十分神奇,对平时手机app是怎么工作与设计的有了浅显的认识,但是在安装Android Stuidio时尤其是SDK时较为繁琐。通过这次实验让我学到了较为有趣与新奇的知识,还需要继续努力坚持。
  • 相关阅读:
    用自己的算法实现startsWith和endsWith功能
    随机生成4位验证码,由用户输入并验证是否输入正确,如果输入错误就生成新的验证码让用户重新输入,最多输入5次
    二分法(网上查找结果)
    模拟摇奖:从1-36中随机抽出8个不重复的数字
    冒泡排序
    输入年龄输出年龄段
    水仙花数
    百钱买百鸡
    百马百担的问题
    控制台输出九九乘法表
  • 原文地址:https://www.cnblogs.com/zyzgl/p/10871600.html
Copyright © 2011-2022 走看看