• 2018-2019-2 20175227张雪莹《Java程序设计》实验四 《Android程序设计》


    2018-2019-2 20175227张雪莹《Java程序设计》

    实验四 《Android程序设计》

    实验报告封面

    • 课程:Java程序设计 班级:1752班 姓名:张雪莹 学号:20175227
    • 指导教师:娄嘉鹏 实验日期:2019年5月13日
    • 实验时间:--- 实验序号:实验四
    • 实验名称:Android程序设计
    • 实验题目
    • 实验要求
      • 参考Android开发简易教程
      • 完成云班课中的检查点,也可以先完成实验报告,直接提交。注意不能只有截图,要有知识点,原理,遇到的问题和解决过程等说明。实验报告中一个检查点要有多张截图。
      • 发表实验报告博客,标题“学期(如2018-2019-2) 学号(如20175300) 实验四《Android开发基础》实验报告”

    实验步骤

    • Android Studio 的安装测试
      • 要求:
        • 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_main.xml中,通过Common Attributes->text内容改为Hello World! 20165318 20165317 20165319
        • 也可以在代码中修改第十二行代码为:android:text="Hello World!20175227 20175226 20175228"
          如图

    • Activity测试
      • 要求:
        • 参考《Java和Android开发学习指南(第二版)(EPUBIT,Java for Android 2nd)》第二十五章:
        • 构建项目,运行教材相关代码
        • 创建 ThirdActivity, 在ThirdActivity中显示自己的学号,修改代码让MainActivity启动ThirdActivity
        • 提交代码运行截图和码云Git链接,截图要有学号水印,否则会扣分
      • 实现过程
        • 选中Java文件夹下的目录文件->File->New->Activity->Empty Activity,新建一个activity,对其命名为:ThirdActivity,单击finish

    • MainActicity.java中增加包package com.example.helloworld;并增加代码:

       Intent intent = new Intent(this,ThirdActivity.class);
       startActivity(intent);
      
      • 运行结果为:

    • UI测试
      • 要求
        • 参考《Java和Android开发学习指南(第二版)(EPUBIT,Java for Android 2nd)》第二十六章:
        • 构建项目,运行教材相关代码
        • 修改代码让Toast消息中显示自己的学号信息
        • 提交代码运行截图和码云Git链接,截图要有学号水印,否则会扣分
      • 实现过程
        • 在MainActivity.java中增加如下代码:
    Toast toast=Toast.makeText(MainActivity.this, "20175227张雪莹",Toast.LENGTH_LONG);
     toast.show();
    

    如图:

    • 运行结果:

    • 布局测试
      • 要求
        • 参考《Java和Android开发学习指南(第二版)(EPUBIT,Java for Android 2nd)》第二十七章:
        • 构建项目,运行教材相关代码
        • 修改布局让P290页的界面与教材不同
        • 提交代码运行截图和码云Git链接,截图要有学号水印,否则会扣分
      • 布局的类型
        • 线性布局LinearLayout:线性布局是一个视图组(ViewGroup),能在水平或者垂直的单一方向上将所有子元素排成一行
        • 相对布局RelativeLayout:相对布局是一个将子视图显示在相对的位置上的布局
        • 表格布局TableLayout:表格布局是在行、列中组合子元素的视图
        • 绝对布局AbsoluteLayout:绝对布局能让你指定子元素的精确位置
        • 帧布局FrameLayout:帧布局是一个屏幕上的占位符,你可以用它来显示单一视图
        • 列表视图ListView:列表布局是可以滚动的,是用于显示子元素列表的视图组
        • 网格视图GridView:网格视图是在二维可滚动的网格中显示子元素的视图组
      • 代码为:
    <RelativeLayout
        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"
        android:paddingLeft="2dp"
        android:paddingRight="2dp">
        <Button
            android:id="@+id/cancelButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="20175227"
            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_dialog_email"
            android:id="@+id/imageView"
            android:layout_below="@+id/saveButton"
            android:layout_centerHorizontal="true" />
        <LinearLayout
            android: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" >
            <Button
                android:id="@+id/filterButton"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:text="Filter" />
            <Button
                android:id="@+id/shareButton"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:text="Share" />
            <Button
                android:id="@+id/deleteButton"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:text="Delete" />
        </LinearLayout>
    
        <ImageButton
            android:id="@+id/imageButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            android:layout_marginBottom="160dp"
            app:srcCompat="@mipmap/ic_launcher" />
    </RelativeLayout>
    
    • 运行结果:

    • 事件处理测试
      • 要求
        • 参考《Java和Android开发学习指南(第二版)(EPUBIT,Java for Android 2nd)》第二十八章:
        • 构建项目,运行教材相关代码
        • 提交代码运行截图和码云Git链接,截图要有学号水印,否则会扣分
      • 实现过程: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"
        tools:context=".MainActivity">
        <AnalogClock
            android: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" />
        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="20175227张雪莹"
            android:layout_marginLeft="70dp"
            android:layout_marginTop="300dp"
            android:textSize="21dp"/>
    </RelativeLayout>
    
    
    • 运行结果:

    实验中遇到的问题和解决过程

    • 问题1:在运行MainActivity.java时,总是出错,根据提示猜测可能是联网失败、Intel x86的某个包未下载,排除以上原因后还是无法运行。

    • 问题1解决办法:尝试自行修改了settings目录下的两处,如图


    下载了两个SDK Platform


    取消了上面的勾选

    程序正确运行,如图:

    代码托管

    参考资料

  • 相关阅读:
    Android各版本系统源代码下载
    Android ListView从网络获取图片及文字显示
    Android 仿QQ主页面的实
    Android ListView初步
    SQLite数据库的使用
    Android ViewPager使用详解
    (转载)在Android中使用Handler和Thread线程执行后台操作
    Android常用的工具类收藏用
    IBM HACMP 系列 后期安装工作和管理任务一
    ORA02024: Database Link Not Found [ID 1058949.1]
  • 原文地址:https://www.cnblogs.com/zxy20175227/p/10862219.html
Copyright © 2020-2023  润新知