太原理工大学12级软件学院Android实验报告

太原理工大学12级软件学院Android实验报告
太原理工大学12级软件学院Android实验报告

本科实验报告

课程名称:移动应用软件开发技术

实验项目:Android系统环境搭建、Activity运用实

验、Android应用UI设计(一)、(二)实验地点:逸夫楼404

专业班级:软件班学号:

学生姓名:

指导教师:

2015年6月19 日

实验一Android系统环境搭建

一、实验目的和要求

1.掌握Android环境的搭建。

2.学会Java、eclipse、Android SDK以及ADT的安装与环境变量设置。

3.学会在线更新SDK。

4.掌握离线安装SDK的方法。

二、实验内容和原理

1.安装JDK ,SE6.0以上版本。

⑴访问以下网址:

https://www.360docs.net/doc/651192303.html,/technetwork/java/javase/downloads/index.html下载JDK。

⑵配置环境变量:安装J2SDK以后,若需要在cmd下使用Java命令和编译、运行程序,

可以配置环境变量:新建环境变量JAVA_HOME,右击“我的电脑”—>“属性”—>“高级”—>“环境变量”,如图1-1所示:

图1-1

⑶测试JDK安装成功与否:编写test.java文件,运行。

要求:请将安装的目录与环境变量的配置图粘到后面的空白页上。并将test.java在运行结果粘上。

2.安装eclipse。

访问以下网址:https://www.360docs.net/doc/651192303.html,/downloads/下载。选择Windows平台“EclipseIDE for Java EE Developers”下载,下载完成后,找到下载的压缩包“eclipse-java-indigo-SR2-win32.zip”,Eclipse无须安装程序,解压此压缩文件到目标文件即可。

要求:请将安装的目录与eclipse环境的界面图粘到后面的空白页上。

3.安装Android SDK

[1]访问以下网址下载:https://www.360docs.net/doc/651192303.html,/sdk/index.html

[2]在线安装SDK:打开SDKManager,如图1-2、1-3所示。

图1-2 图1-3

[3]离线安装:首先下载SDK的安装包,“android-sdk_r16-windows.zip”(安装工具)解压到目录,如我的目录D:\TDDOWNLOAD\android-sdk_r16-windows\android-sdk-windows,然后新建以下几个文件夹:platforms,docs,samples,usb_driver,market_licensing。接着打开下载工具,下载以下内容:

https://www.360docs.net/doc/651192303.html,/android/repository/android-1.5_r04-windows.zip

https://www.360docs.net/doc/651192303.html,/android/repository/android-1.6_r03-windows.zip

https://www.360docs.net/doc/651192303.html,/android/repository/android-2.0.1_r01-windows.zip

https://www.360docs.net/doc/651192303.html,/android/repository/android-2.0_r01-windows.zip

https://www.360docs.net/doc/651192303.html,/android/repository/android-2.1_r02-windows.zip

https://www.360docs.net/doc/651192303.html,/android/repository/android-2.2_r01-windows.zip

https://www.360docs.net/doc/651192303.html,/android/repository/docs-2.2_r01-linux.zip

https://www.360docs.net/doc/651192303.html,/android/repository/google_apis-3-r03.zip

https://www.360docs.net/doc/651192303.html,/android/repository/google_apis-4_r02.zip

https://www.360docs.net/doc/651192303.html,/android/repository/google_apis-5_r01.zip

https://www.360docs.net/doc/651192303.html,/android/repository/google_apis-6_r01.zip

https://www.360docs.net/doc/651192303.html,/android/repository/google_apis-7_r01.zip

https://www.360docs.net/doc/651192303.html,/android/repository/google_apis-8_r01.zip

https://www.360docs.net/doc/651192303.html,/android/repository/jboss-5.1.0.GA.zip

https://www.360docs.net/doc/651192303.html,/android/repository/samples-2.1_r01-linux.zip

https://www.360docs.net/doc/651192303.html,/android/repository/samples-2.2_r01-linux.zip

https://www.360docs.net/doc/651192303.html,/android/repository/tools_r06-windows.zip

https://www.360docs.net/doc/651192303.html,/android/repository/usb_driver_r03-windows.zip

要求:请将安装的目录与SDK在界面图粘到后面的空白页上。

4.安装ADT

[1]首先启动Eclipse,选择Help->Install New Software,打开Eclipse的插件安装页面。

[2]单击Add按钮,弹出“Add Repository”对话框,在Name中输入:ADT,在Location 中输入:https://www.360docs.net/doc/651192303.html,/android/eclipse/,单击OK按钮后,Eclipse会自动搜索可安装的插件。

[3] 此时Eclipse会搜索指定URI的资源,如果搜索无误,会出现:Develop Tools的复选框,选中复选框,点击“Next”按钮。再点击finish 按钮

[4] 整个安装过程会持续几分钟,安装结束后会出现Eclipse重启提示界面,。建议选择

“Restart Now”按钮重新启动Eclipse,使ADT插件生效。

[5]在ADT插件安装完毕且重启Eclipse之后,进入配置Android开发环境的最后一步,

设置Android SDK的位置。首先选择Windows->Preference命令打开Eclipse的配制界面,然后在SDK Location 中输入Android SDK的保存路径,最后单击OK按钮使配置生效。

要求:请将安装ADT后的eclipse界面图粘到后面的空白页上。

三、主要仪器设备

hp笔记本

四、实验结果与分析

1.jdk安装:

安装目录:

环境变量配置:

2.eclipse安装:

3.SDK安装:

4.安装ADT后eclipse:

实验二Activity运用实验

一、实验目的和要求

1.熟悉Activity与Intent的使用。

2.掌握Activity启动另一个Activity的方法。

3.会使用Intent对象进行Activity间意图的传达。

二、实验内容和原理

1.编一Android应用程序TestActivity01,使用MainActivity,启动另一个OtherActivity。

MainActivity主界面上只有一个按钮。OtherActivity上只有一个TextView组件。

要求:请将工程中的MainActivity.java,OtherActivity.java以及对应的xml文件源码附上。同时将运行的界面图粘上。

2.编一Android应用程序TestActivity02,使用MainActivity,启动另一个OtherActivity。

MainActivity主界面上只有一个按钮。OtherActivity上只有一个TextView组件。要将MainActivity中的数据“中国”通过Intent对象传到OtherActivity上显示。

要求:请将工程中的MainActivity.java,OtherActivity.java以及对应的xml文件源码附上。同时将运行的界面图粘上。

三、主要仪器设备

hp笔记本

四、实验结果与分析

MainActivity.java:

package com.example.intent1;

import android.support.v7.app.ActionBarActivity;

import android.text.Editable;

import android.content.Intent;

import android.os.Bundle;

import android.view.Menu;

import android.view.MenuItem;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.Button;

import android.widget.EditText;

import android.widget.TextView;

public class MainActivity extends ActionBarActivity {

private Button but;

private TextView bibi;

@Override

protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);

setContentView(https://www.360docs.net/doc/651192303.html,yout.activity_main);

but=(Button) findViewById(R.id.but);

bibi=(TextView) findViewById(R.id.bibi);

but.setOnClickListener(new OnClickListener() {

@Override

public void onClick(View v) {

// TODO Auto-generated method stub

Intent intent=new Intent();

String msg=(String) MainActivity.this.bibi.getText(); intent.putExtra("bibi", msg);

intent.setClass(MainActivity.this,OtherActivity.class);

}

});

}

}

OtherActivity.java代码:

package com.example.intent1;

import android.app.Activity;

import android.content.Intent;

import android.os.Bundle;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.Button;

import android.widget.TextView;

public class OtherActivity extends Activity{

private TextView jieguo;

private Button bu;

@Override

protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub

super.onCreate(savedInstanceState);

setContentView(https://www.360docs.net/doc/651192303.html,yout.factivity);

jieguo=(TextView) findViewById(R.id.jieguo);

bu=(Button) findViewById(R.id.bu);

Intent intent=getIntent();

String msg=intent.getStringExtra("bibi");

OtherActivity.this.jieguo.setText(msg);

bu.setOnClickListener(new OnClickListener() {

@Override

public void onClick(View v) {

// TODO Auto-generated method stub

Intent intent=new Intent();

intent.setClass(OtherActivity.this,NextActivity.class);

startActivity(intent);

}

});

}

}

activity_main.xml;

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:orientation="vertical" >

android:id="@+id/but"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="点我" />

android:id="@+id/bibi"

android:layout_width="match_parent"

android:layout_height="40dp"

android:hint="结果"

android:textColor="#ff0000"

android:textSize="30dp"

/>

android:id="@+id/babi"

android:layout_width="match_parent"

android:layout_height="40dp"

android:hint="请输入"

/>

android:id="@+id/but1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="点我哦" />

factivity.xml:

android:layout_height="match_parent"

android:orientation="vertical" >

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:orientation="vertical" >

android:id="@+id/jieguo"

android:layout_width="match_parent"

android:layout_height="60dip"

android:hint="结果"/>

android:id="@+id/bu"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="返回" />

实验结果:

实验三Android应用UI设计(一)

一、实验目的和要求

1.熟悉TextView、Button、ImageView、LinearLayout、TabelLayout、RelativeLayout、FrameLayout、AlertDialog对话框。

2.掌握以上UI设计元素的基本功能和用法。

3.掌握UI设计的基本方法。

二、实验内容和原理

(一)实现一个如图3.1所示的UI界面

1.布局分析:最外层是纵向的线性布局(LinearLayout,android:orientation="vertical"),包含了三个布局,横向的线性布局(四列)、表格布局(TableLayout,三行三列)、纵向的线性布局(四行)。

2.在res\layout文件夹下的MyLayout.xml中实现。

3.布局内的控件为TextView

要求:请将工程中的java源文件以及对应的xml文件源码附上。同时将运行的界面图粘上。

图3.1布局嵌套图3.2多输入对话框

(二)实现一个如图3.2所示的多输入框的对话框

1.要求使用LinearLayout布局、TextView、EditText控件各两个。

2.要求点击按钮后有对应的输出(用Toast控件、TextView控件以及Logcat窗口输出都可以)。

要求:请将工程中的java源文件以及对应的xml文件源码附上。同时将运行的界面图粘上。

三、主要仪器设备

hp笔记本电脑

四、实验结果与分析

(一)实现UI界面

实验代码:

activity_main.xml:

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:orientation="vertical" >

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:orientation="horizontal"

android:layout_weight="4"

android:text="@string/color1"

android:textSize="7pt"

android:textColor="#000000"

android:background="#ff0000"

android:gravity="center_vertical|center_horizontal"

android:layout_width="wrap_content"

android:layout_height="fill_parent"

android:layout_weight="1"

/>

android:text="@string/color2"

android:textColor="#000000"

android:background="#00ff00"

android:gravity="center_vertical|center_horizontal"

android:layout_width="wrap_content"

android:layout_height="fill_parent"

android:layout_weight="1"

/>

android:text="@string/color3"

android:textSize="7pt"

android:textColor="#000000"

android:background="#0000ff"

android:gravity="center_vertical|center_horizontal"

android:layout_width="wrap_content"

android:layout_height="fill_parent"

android:layout_weight="1"

/>

android:text="@string/color4"

android:textSize="7pt"

android:textColor="#000000"

android:background="#ffff00"

android:gravity="center_vertical|center_horizontal"

android:layout_width="wrap_content"

android:layout_height="fill_parent"

android:layout_weight="1"

/>

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:orientation="vertical"

android:layout_weight="1">

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:stretchColumns="1">

android:id="@+id/row1"

android:layout_width="wrap_content"

android:layout_height="wrap_content" >

android:text="@string/row1_column1"

android:gravity="center_horizontal"

/>

android:text="@string/row1_column2"

android:gravity="center_horizontal" android:padding="3dip"

/>

android:text="@string/row1_column3"

android:gravity="center_horizontal" android:padding="3dip"

/>

android:id="@+id/row2"

android:layout_width="wrap_content"

android:layout_height="wrap_content" >

android:text="@string/row2_column1"

android:gravity="center_horizontal"

android:padding="3dip"

/>

android:text="@string/row2_column2"

android:gravity="center_horizontal"

android:padding="3dip"

/>

android:text="@string/row2_column3"

android:gravity="center_horizontal"

android:padding="3dip"

/>

android:id="@+id/row3"

android:layout_width="wrap_content"

android:layout_height="wrap_content" >

android:text="@string/row3_column1"

android:gravity="center_horizontal"

android:padding="3dip"

/>

android:text="@string/row3_column2"

android:gravity="center_horizontal"

android:padding="3dip"

/>

android:text="@string/row3_column3"

android:gravity="center_horizontal"

android:padding="3dip"

/>

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:orientation="vertical"

android:layout_weight="2">

android:text="@string/color1"

android:textSize="7pt"

android:textColor="#000000"

android:background="#ff0000"

android:gravity="center_vertical|center_horizontal" android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:layout_weight="1"

/>

android:text="@string/color2"

android:textSize="7pt"

android:textColor="#000000"

android:background="#00ff00"

android:gravity="center_vertical|center_horizontal" android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:layout_weight="1"

/>

android:text="@string/color3"

android:textSize="7pt"

android:textColor="#000000"

android:background="#0000ff"

android:gravity="center_vertical|center_horizontal" android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:layout_weight="1"

/>

android:text="@string/color4"

android:textSize="7pt"

android:textColor="#000000"

android:background="#ffff00"

android:gravity="center_vertical|center_horizontal" android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:layout_weight="1"

/>

实验结果:

(二)实现一个多输入框的对话框

实验代码:

activity_main.xml:

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical"android:padding="20.0dip">

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:orientation="horizontal">

android:text="@string/name"

android:layout_width="wrap_content"

android:layout_height="wrap_content"/>

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:inputType="none"/>

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:orientation="horizontal">

android:text="@string/pnumber"

android:layout_width="wrap_content"

android:layout_height="wrap_content"/>

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:inputType="phone"/>

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:orientation="horizontal">

android:text="@string/email"

android:layout_width="wrap_content"

android:layout_height="wrap_content"/>

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:inputType="textEmailAddress"/>

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:orientation="horizontal">