8001511072夏先国实验六第七章Android基本控件下.docx
《8001511072夏先国实验六第七章Android基本控件下.docx》由会员分享,可在线阅读,更多相关《8001511072夏先国实验六第七章Android基本控件下.docx(16页珍藏版)》请在冰豆网上搜索。
8001511072夏先国实验六第七章Android基本控件下
南昌大学实验报告
学生姓名:
夏先国学号8001511072专业班级:
软件技术112班
实验类型:
□验证□综合
设计□创新实验日期:
2013-05-08实验成绩:
一、实验项目名称
Android中的基本控件(下)
二、实验目的
经一步掌握安卓中的控件
三、实验要求
完成以下实验
1.滚动视图ScrollView
2.列表显示ListView
3.对话框Dialog
4.随笔提示文本Dialog
5.滚动条SeekBar
6.评分组件RatingBar
四、主要仪器设备及耗材
PC机一台,JDK,eclispce,sdk
五、实验步骤及处理结果
1.滚动视图ScrollView
main.xml
xmlversion="1.0"encoding="utf-8"?
>
android:
id="@+id/myscroll"
xmlns:
android="
android:
layout_width="fill_parent"
android:
layout_height="fill_parent">
xmlns:
android="
android:
orientation="vertical"
android:
id="@+id/mylinear"
android:
layout_width="fill_parent"
android:
layout_height="fill_parent">
Activity
packageorg.lxh.demo;
importandroid.app.Activity;
importandroid.os.Bundle;
importandroid.view.ViewGroup;
importandroid.widget.Button;
importandroid.widget.LinearLayout;
publicclassMyScrollViewDemoextendsActivity{
privateStringdata[]={"北京魔乐科技","","讲师:
李兴华",
"中国高校讲师联盟","","咨询邮箱:
mldnqa@",
"客户服务:
mldnkf@","客户电话:
(010)51283346","魔乐社区:
",
"程序员招聘网:
};//准备出若干个信息而这些信息以后将通过程序加入到内嵌的线性布局文件之中
@Override
publicvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
super.setContentView(R.layout.main);//调用默认的布局管理器
LinearLayoutlayout=(LinearLayout)super.findViewById(R.id.mylinear);//取得组件
LinearLayout.LayoutParamsparam=newLinearLayout.LayoutParams(
ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT);//定义布局参数
for(intx=0;xButtonbut=newButton(this);
but.setText(this.data[x]);//设置显示文字
layout.addView(but,param);//增加组件
}
}
}
效果截图:
2.列表显示ListView
main.xml
xmlversion="1.0"encoding="utf-8"?
>
android="
android:
orientation="vertical"
android:
layout_width="fill_parent"
android:
layout_height="fill_parent"
>
android:
layout_width="fill_parent"
android:
layout_height="wrap_content"
android:
text="@string/hello"
/>
Activity
packageorg.lxh.demo;
importandroid.app.Activity;
importandroid.os.Bundle;
importandroid.widget.ArrayAdapter;
importandroid.widget.ListView;
publicclassMyListViewDemoextendsActivity{
privateStringdata[]={"北京魔乐科技","","讲师:
李兴华",
"中国高校讲师联盟","","咨询邮箱:
mldnqa@",
"客户服务:
mldnkf@","客户电话:
(010)51283346","魔乐社区:
",
"程序员招聘网:
};//准备出若干个信息而这些信息以后将通过程序加入到内嵌的线性布局文件之中
privateListViewlistView=null;//定义ListView组件
@Override
publicvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
this.listView=newListView(this);//实例化组件
this.listView.setAdapter(newArrayAdapter(this,
android.R.layout.simple_expandable_list_item_1,this.data));//为ListView组件设置内容
super.setContentView(this.listView);//显示组件
}
}
效果截图:
3.对话框Dialog
main.xml
xmlversion="1.0"encoding="utf-8"?
>
android="
android:
orientation="vertical"android:
layout_width="fill_parent"
android:
layout_height="fill_parent">