20175212童皓桢 实验四 Android程序设计

实验内容

  • 参考《Java和Android开发学习指南(第二版)(EPUBIT,Java for Android 2nd)》并完成相关学习

实验步骤

一、Android Stuidio的安装测试

任务一要求:

  • 参考http://www.cnblogs.com/rocedu/p/6371315.html#SECANDROID,安装Android Stuidio
  • 完成Hello World, 要求修改res目录中的内容,Hello World后要显示自己的学号,自己学号前后一名同学的学号
  • 学习Android Stuidio调试应用程序

实验过程:

  • 将MainActivity.java中,选择text界面,将android:text="Hello World!"修改为
android:text="Hello World20175212 20175211 20175213!"

  • 将MainActivity.java中,选择design图形界面,选中中间的文本框进行编辑,输入
"Hello World20175212 20175211 20175213!"

  • 运行结果:

二、Activity测试

任务二要求:

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

    实验过程
  1. MainActivity相同的目录下创建ThirdActivity项目
  2. 按照修改MainActivity中相关代码
  3. 修改在layout中activity_third.xml文件,具体是
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="20175212童皓桢" /> - MainActivity.java
package com.example.helloworld; import android.content.Intent;
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.activity_main);
Intent intent = new Intent(this,ThirdActivity.class);
startActivity(intent); }
} - Activity_third.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=".ThirdActivity"> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="20175212童皓桢" /> </android.support.constraint.ConstraintLayout>

运行结果:

三、UI测试

任务三要求:

  • 构建项目,运行教材相关代码
  • 修改代码让Toast消息中显示自己的学号信息
  • 提交代码运行截图和码云Git链接
  • MainActivity.java
package com.example.helloworld;

import android.content.Intent;
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 toast=Toast.makeText(MainActivity.this, "20175212童皓桢", Toast.LENGTH_LONG);
toast.show(); }
}

运行结果:

四、布局测试

任务四要求:

  • 构建项目,运行教材相关代码
  • 修改布局让P290页的界面与教材不同
  • 提交代码运行截图和码云Git链接,截图要有学号水印
  • activity_main.xml
<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="20175212"
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"
and

运行结果:

五、事件处理测试

  • 构建项目,运行教材相关代码
  • 提交代码运行截图和码云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="20175212 童皓桢"
android:layout_marginLeft="60dp"
android:layout_marginTop="300dp"
android:textSize="16dp"/>
</RelativeLayout>

运行结果:

实验中遇到的问题

  • 问题一:Android Studio中出现Java未识别文件,并且无法正常编译运行。(类名前为红J)

  • 解决办法一:在左边目录中找到build.gradle文件,点击Sync Project with Gradle File。或者参考https://www.cnblogs.com/kissfu/p/6093335.html添加代码,即可解决。

参考博客

https://www.cnblogs.com/kissfu/p/6093335.html

最新文章

  1. 【Java EE 学习 73】【数据采集系统第五天】【参与调查】【导航处理】【答案回显】【保存答案】
  2. 解决COM组件80070005错误
  3. 第三章Git使用入门--读书笔记
  4. 部署基于国际版Azure的SharePoint三层架构服务器场
  5. js动态生成表格
  6. hdu 1290 切糕
  7. 攻城狮在路上(壹) Hibernate(十四)--- Hibernate的检索方式(下)
  8. IOS网络开发(一)
  9. struts2中valueStack,stackContext以及actionContext的关系
  10. grunt构建前端自动化
  11. 解析JavaScript中apply和call以及bind
  12. Python实现ID3算法
  13. [solaris]odbc-oracle,简单测试
  14. Java采用HttpClient对于Web登录
  15. 读书笔记 effective c++ Item 2 尽量使用const,枚举(enums),内联(inlines),不要使用宏定义(define)
  16. Hibernate5.3 + mysql8.0遇到的问题
  17. 你电梯没了—OO第二单元作业思考
  18. Is-a
  19. windows下django1.7 +python3.4.2搭建记录1
  20. Downloading jQuery 3.2.1

热门文章

  1. 11 Mysql之配置双主热备+keeepalived.md
  2. 01 初识HTML
  3. axios设置了responseType: &#39;json‘’,ie问题
  4. Js 将图片的绝对路径转换为base64编码(3)
  5. Delphi BitBtn组件
  6. 10.1、LNMT架构
  7. poj 1458 Common Subsequence(dp)
  8. MongoDB的优势应用场景和配置
  9. 解决Jenkins忘记用户名,密码
  10. DB2中常见sqlCode原因分析