Android Stuidio的安装测试:

完成Hello World, 要求修改res目录中的内容,Hello World后要显示自己的学号

·实验过程

完成任务一,只需在Android应用程序文件中修改布局文件中的android:text="Hello World!" 将引号里面的英文单词替换成自己的学号即可。

运行结果:

Activity测试:

创建 ThirdActivity, 在ThirdActivity中显示自己的学号,修改代码让MainActivity启动ThirdActivity

·实验过程:

首先实验要求我们在MainActivity中启动ThirdActivity,这就需要我们配置一个Activity,即在AndroidManifest.xml中添加Activity,并修改相应的布局文件让其启动。从教材上我们能了解到怎样修改布局文件,即添加相应代码即可:

@Override

public boolean onTouch(View arg0, MotionEvent event) {

Intent intent = new Intent(this, ThirdActivity.class);

intent.putExtra("message", "20162319莫礼钟");

startActivity(intent);

return true;

UI测试:

构建项目,运行教材相关代码

修改代码让Toast消息中显示自己的学号信息

·实验过程:

修改相应代码

activity_main:

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="20162319莫礼钟"
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" />

MainActivity.java:
@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,"20162319莫礼钟", Toast.LENGTH_LONG);
toast.show();
} });
运行结果:
(截图)
## 布局测试
修改布局让P290页的界面与教材不同
## ·实验过程
首先我们先来了解一下Android中的一些布局:
1.线性布局LinearLayout:将所有子视图以相同方向(水平地或竖直地)对齐的一个布局;
2.相对布局RelativeLayout:根据子视图的一个或多个同级视图的位置来排列它的一个布局;
3.帧布局FrameLayout:将每一个子视图放在另一个视图顶部的一种布局;
4.表格布局TableLayout:将子视图按照行和列来组织的一种布局;
5.网格布局GridLayout:将子视图放置到一个栅格中的一种布局
然后在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:paddingLeft="2dp"

android:paddingRight="2dp">

<Button

    android:id="@+id/cancelButton"

    android:layout_width="wrap_content"

    android:layout_height="wrap_content"

    android:text="20162319"

    android:layout_above="@+id/saveButton"

    android:layout_centerHorizontal="true"

    android:layout_marginBottom="16dp" />

<Button

    android:id="@+id/saveButton"

    android:layout_width="wrap_content"

    android:layout_height="wrap_content"

    android:text="莫礼钟"

    android:layout_above="@+id/imageView"

    android:layout_alignLeft="@+id/deleteButton"

    android:layout_alignStart="@+id/deleteButton"

    android:layout_marginBottom="13dp" />

<ImageView

    android:layout_width="150dp"

    android:layout_height="150dp"

    android:padding="4dp"

    android:src="@android:drawable/ic_dialog_email"

    android:id="@+id/imageView"

    android:layout_alignParentBottom="true"

    android:layout_centerHorizontal="true"

    android:layout_marginBottom="54dp" />

<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" >

</LinearLayout>

<Button

    android:id="@+id/filterButton"

    android:layout_width="80dp"

    android:layout_height="90dp"

    android:text="前进"
android:layout_below="@+id/deleteButton"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="22dp" /> <Button android:id="@+id/deleteButton" android:layout_width="80dp" android:layout_height="90dp" android:text="暂停" android:layout_above="@+id/cancelButton"
android:layout_centerHorizontal="true" /> <Button android:id="@+id/shareButton" android:layout_width="80dp" android:layout_height="90dp" android:text="后退" android:layout_alignBottom="@+id/saveButton"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />

运行结果:
![](http://images2015.cnblogs.com/blog/1063999/201706/1063999-20170602132201977-994929022.png)

事件处理测试:

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

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

·实验过程:

运用view.setBackgroundColor(colors[counter++]传入颜色对象。

代码如下:public class MainActivity extends AppCompatActivity {

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

}

运行结果:

实验感想

其实在实验中碰到了很多小问题,但其中最让我头疼的就是R的丢失问题,后来我试了一下重新建立一个新项目,发现R又不报错了。王老师说可能是因为教材上的代码跟我们现在用的版本有一点不兼容,所以写代码的时候不能复制粘贴而是根据教材上的提示自己写出代码,这样就不会出现问题。

后来我找到了一篇博客。希望以后自己能用这个程序设计出象棋游戏。

20162319 实验四 Android程序设计的更多相关文章

  1. 实验四 Android程序设计 实验报告

    实验四 Android程序设计 实验报告 目录 代码托管地址 Android程序设计-1 Android程序设计-2 Android程序设计-3 Android程序设计-4 Android程序设计-5 ...

  2. 第十四周实验报告:实验四 Android程序设计

    20162317袁逸灏 第十四周实验报告:实验四 Android程序设计 实验内容 Android Studio 实验要求 学会使用Android Studio 学习 活动 以及相关知识内容 学习 U ...

  3. 20165235实验四 Android程序设计

    20165235实验四 Android程序设计 实验课程:JAVA编程设计 实验名称:Android开发 姓名:祁瑛 学号:20165235 实验时间:2018.05.16 指导老师:娄家鹏 Andr ...

  4. 20165220Java实验四 Android程序设计

    一.实验报告封面 课程:Java程序设计 班级:1652班 姓名:葛宇豪 学号:20165220 指导教师:娄嘉鹏 实验日期:2018年5月14日 实验时间:13:45 - 15:25 实验序号:实验 ...

  5. 20172328《程序设计与数据结构》实验四 Android程序设计报告

    20172328<程序设计与数据结构>实验四 Android程序设计报告 课程:<程序设计与数据结构> 班级: 1723 姓名: 李馨雨 学号:20172328 实验教师:王志 ...

  6. 20172302《程序设计与数据结构》实验四Android程序设计实验报告

    课程:<程序设计与数据结构> 班级: 1723 姓名: 侯泽洋 学号:20172302 实验教师:王志强老师 实验日期:2018年5月30日 必修/选修: 必修 1.实验内容 (1)And ...

  7. 实验四 Android程序设计

    20155224 实验四 Android程序设计 实验报告 实验报告封面: 课程:Java程序设计 班级:1652班 姓名:王高源 学号:20165225 指导教师:娄嘉鹏 实验日期:2018年5月1 ...

  8. 20165236 实验四 Android程序设计

    20165236  实验四 Android程序设计 一.实验报告 课程:Java程序设计          班级:1652班 姓名:郭金涛       学号:20165236 指导教师:娄嘉鹏  实验 ...

  9. 20165205 2017-2018-2 《Java程序设计》实验四 Android程序设计

    20165205 2017-2018-2 <Java程序设计>实验四 Android程序设计 实验内容 实验四 Android程序设计-1 Android Stuidio的安装测试: 参考 ...

随机推荐

  1. 用NDK生成so给第三方用

    参考了https://blog.csdn.net/zi413293813/article/details/50074239 然后自己重新整理补充 我用的ndk-r10d ndk下载地址http://d ...

  2. UITableView 基本使用方法总结

    1..首先,Controller需要实现两个  delegate ,分别是  UITableViewDelegate 和  UITableViewDataSource2.然后 UITableView对 ...

  3. 【数据结构与算法】001—栈与队列(Python)

    栈与队列 1.栈(stacks)是一种只能通过访问其一端来实现数据存储与检索的线性数据结构,具有后进先出(last in first out,LIFO)的特征 2.队列(queue)是一种具有先进先出 ...

  4. python 第一课作用

    1.使用while循环输入 1 2 3 4 5 6     8 9 10 x=0while x<10: x=x+1 if x==7: print(' ') continue print(x)#学 ...

  5. 菜鸟成长心酸史之php初遇教程

    phpstorm是我接触到的第二个制作网页的程序,刚拿到php的时候,我是懵逼的,从安装到使用,可以说一点都不会,尤其是它还要配合wampsever使用,即使看视频,不同的制作php的软件也有不同的地 ...

  6. Win10 安装 MongoDB 3.6.5 失败的问题

    MongoDB 3.6.5 2008R2Plus SSL (64 bit) Setup Wizard ended prematurely 在安装 MongoDB 的时候,出现了MongoDB 3.6. ...

  7. JavaWeb基础—JavaBean

    一.什么是JavaBean 一个遵循一定规范的普通的Java类 百度的JavaBean规范: (1)JavaBean 类必须是一个公共类,并将其访问属性设置为 public , 如: public c ...

  8. Oracle单节点_Grid_Infrastructure_DB_安装过程图解(二/三)

    接上文 Oracle单节点_Grid_Infrastructure_DB_安装过程图解(一/三) 接下来,进行Grid Infrastructure 部分的安装:

  9. Openstack入门篇(十八)之Cinder服务-->使用NFS作为后端存储

    1.安装cinder-volume组件以及nfs [root@linux-node2 ~]# yum install -y openstack-cinder python-keystone [root ...

  10. doc2vec使用笔记

    #!/usr/bin/env Python # coding:utf-8 #improt依赖包 # import sys # reload(sys) # sys.setdefaultencoding( ...