最新android本科实验报告.doc
精品资料android本科实验报告.本科实验报告课程名称: Android设计与开发 实验项目: Android 课程实验 实验地点: 逸夫楼404 专业班级: 学号: 学生姓名: 指导教师: 年 月 日太原理工大学学生实验报告学院名称软件学院专业班级 学号 学生姓名 实验日期2013/5成绩课程名称Android设计与开发实验题目Android系统环境搭建实验一 Android系统环境搭建一、目的与要求1掌握Android环境的搭建。2学会Java、eclipse、Android SDK以及ADT的安装与环境变量设置。3学会在线更新SDK。4掌握离线安装SDK的方法。二、实验内容1安装JDK ,SE6.0以上版本。 访问以下网址:。配置环境变量:安装J2SDK以后,若需要在cmd下使用Java命令和编译、运行程序,可以配置环境变量:新建环境变量JAVA_HOME,右击“我的电脑”>“属性”>“高级”>“环境变量”,如图1-1所示:图1-1 测试JDK安装成功与否:编写test.java文件,运行。要求:请将安装的目录与环境变量的配置图粘到后面的空白页上。并将test.java在运行结果粘上。2安装eclipse。访问以下网址:http:/www.eclipse.org/downloads/下载。选择Windows平台“EclipseIDE for Java EE Developers”下载,下载完成后,找到下载的压缩包“eclipse-java-indigo-SR2-win32.zip”,Eclipse无须安装程序,解压此压缩文件到目标 文件即可。要求:请将安装的目录与eclipse环境的界面图粘到后面的空白页上。3安装Android SDK1访问以下网址下载: 2在线安装SDK:打开SDKManager,如图1-2、1-3所示。 图1-2 图1-33离线安装:首先下载SDK的安装包,“android-sdk_r16-windows.zip”(安装工具)解压到目录,如我的目录D:TDDOWNLOADandroid-sdk_r16-windowsandroid-sdk-windows,然后新建以下几个文件夹:platforms,docs,samples,usb_driver,market_licensing。接着打开下载工具,下载以下内容: http:/dl-http:/dl-http:/dl-http:/dl-http:/dl-http:/dl-http:/dl-http:/dl-http:/dl-http:/dl-http:/dl-http:/dl-http:/dl-http:/dl-http:/dl-http:/dl-http:/dl-要求:请将安装的目录与SDK在界面图粘到后面的空白页上。4安装ADT1 首先启动Eclipse,选择Help->Install New Software,打开Eclipse的插件安装页面。2 单击Add按钮,弹出“Add Repository”对话框,在Name中输入:ADT,在Location中输入:,单击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界面图粘到后面的空白页上。5. 总结实验心得。 Android 系统搭建之中学到了许多,java路径的设置等等,安装ADT。实验地点逸夫楼404指导教师太原理工大学学生实验报告学院名称软件学院专业班级 学号 学生姓名 实验日期2013/5成绩课程名称Android设计与开发实验题目 Activity运用实验实验二 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文件源码附上。同时将运行的界面图粘上。三、 实验结果 public class MainActivity extends Activity private Button btn;Overrideprotected void onCreate(Bundle savedInstanceState) super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);btn=(Button)findViewById(R.id.btn);btn.setOnClickListener(new OnClickListener() Overridepublic void onClick(View v) / TODO Auto-generated method stubIntent intent=new Intent();intent.putExtra("china", "中国");intent.setClass(MainActivity.this, OtherActivity.class);startActivity(intent););Overridepublic boolean onCreateOptionsMenu(Menu menu)/ Inflate the menu; this adds items to the action bar if it is present.getMenuInflater().inflate(R.menu.main, menu);return true;public class OtherActivity extends Activity TextView textv;Overrideprotected void onCreate(Bundle savedInstanceState) super.onCreate(savedInstanceState);setContentView(R.layout.main);Intent intent=getIntent();String china=intent.getStringExtra("china");textv=(TextView)findViewById(R.id.textv);textv.setText(china);Overridepublic boolean onCreateOptionsMenu(Menu menu) / Inflate the menu; this adds items to the action bar if it is present.getMenuInflater().inflate(R.menu.main, menu);return true;<RelativeLayout xmlns:android=" xmlns:tools=" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="dimen/activity_vertical_margin" android:paddingLeft="dimen/activity_horizontal_margin" android:paddingRight="dimen/activity_horizontal_margin" android:paddingTop="dimen/activity_vertical_margin" tools:context=".MainActivity" ><Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="+id/btn" android:text="button" /> </RelativeLayout><?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android=" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TextView android:layout_width="match_parent" android:layout_height="match_parent" android:id="+id/textv" /></LinearLayout>四 实验截图: 五. 实验心得。 Activity 跳转传值中学到了许多,用intent传递值一个activity 往另一个activity传递值。实验地点逸夫楼404指导教师太原理工大学学生实验报告学院名称软件学院专业班级 学号 学生姓名 实验日期2013/5成绩课程名称Android设计与开发实验题目 实验三 android应用UI设计(一)实验三 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在reslayout文件夹下的MyLayout.xml中实现。3布局内的控件为TextView要求:请将工程中的java源文件以及对应的xml文件源码附上。同时将运行的界面图粘上。(二)实现一个如图3.2所示的多输入框的对话框1要求使用LinearLayout布局、TextView、EditText控件各两个。2要求点击按钮后有对应的输出(用Toast控件、TextView控件以及Logcat窗口输出都可以)。 三实验结果 (一)<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android=" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:weightSum="3" > <LinearLayout android:layout_width="match_parent" android:orientation="horizontal" android:layout_weight="1" android:weightSum="4" > <TextView android:layout_weight="1" android:layout_width="wrap_content" android:layout_height="fill_parent" android:background="#FF0000" android:text="red" android:gravity="center" /> <TextView android:layout_weight="1" android:layout_width="wrap_content" android:layout_height="fill_parent" android:background="#00BB00" android:text="green" android:gravity="center" /> <TextView android:layout_weight="1" android:layout_width="wrap_content" android:layout_height="fill_parent" android:background="#0000C6" android:text="blue" android:gravity="center" /> <TextView android:layout_weight="1" android:layout_width="wrap_content" android:layout_height="fill_parent" android:background="#F9F900" android:text="yellow" android:gravity="center" /> </LinearLayout> <TableLayout android:layout_width="fill_parent" android:layout_weight="1" android:background="#000000" > <TableRow android:layout_width="fill_parent" android:layout_height="wrap_content" android:weightSum="3" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="学号" android:gravity="center" android:textColor="#FFFFFF" /> <TextView android:layout_weight="1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="姓名" android:gravity="center" android:textColor="#FFFFFF" /> <TextView android:layout_weight="1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="性别" android:gravity="center" android:textColor="#FFFFFF" /> </TableRow> <TableRow android:layout_width="fill_parent" android:layout_height="wrap_content" android:weightSum="3" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="0001" android:gravity="center" android:textColor="#FFFFFF" /> <TextView android:layout_weight="1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="0000" android:gravity="center" android:textColor="#FFFFFF" /> <TextView android:layout_weight="1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="男" android:gravity="center" android:textColor="#FFFFFF" /> </TableRow> <TableRow android:layout_width="fill_parent" android:layout_height="wrap_content" android:weightSum="3" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="0002" android:gravity="center" android:textColor="#FFFFFF" /> <TextView android:layout_weight="1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="0000" android:gravity="center" android:textColor="#FFFFFF" /> <TextView android:layout_weight="1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="男" android:gravity="center" android:textColor="#FFFFFF" /> </TableRow> </TableLayout> <LinearLayout android:layout_width="fill_parent" android:orientation="vertical" android:weightSum="4" android:layout_weight="1" > <TextView android:layout_width="match_parent" android:background="#FF0000" android:layout_weight="1" android:text="red" android:gravity="center" /> <TextView android:layout_width="match_parent" android:layout_weight="1" android:background="#00BB00" android:text="green" android:gravity="center" /> <TextView android:layout_width="match_parent" android:layout_weight="1" android:background="#0000C6" android:text="blue" android:gravity="center" /> <TextView android:layout_width="match_parent" android:layout_weight="1" android:background="#F9F900" android:text="yellow" android:gravity="center" /></LinearLayout></LinearLayout> 三.实验截图:四、 实验结果 (二)R.layout.adialogm 代码 <?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android=" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="姓名" /> <EditText android:layout_width="fill_parent" android:layout_height="50dip" android:id="+id/editname" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="电话号码" /> <EditText android:layout_width="fill_parent" android:layout_height="50dip" android:id="+id/editiphone" /></LinearLayout>public class MainActivity extends Activity private Button btn;private EditText edit;private EditText editt;Overrideprotected void onCreate(Bundle savedInstanceState) super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);btn=(Button)findViewById(R.id.btn);btn.setOnClickListener(new OnClickListener() Overridepublic void onClick(View