Android基础开发练习三.docx
- 文档编号:30220835
- 上传时间:2023-08-07
- 格式:DOCX
- 页数:42
- 大小:3.37MB
Android基础开发练习三.docx
《Android基础开发练习三.docx》由会员分享,可在线阅读,更多相关《Android基础开发练习三.docx(42页珍藏版)》请在冰豆网上搜索。
Android基础开发练习三
实验3Android界面控件与布局
实验目的:
1.掌握Android常用界面控件的使用方法。
2.掌握控件响应函数的编写方法。
3.掌握各种界面布局的特点和使用方法。
实验内容与步骤:
1.使用TabHost(Tab标签页)建立3个标签页,每个标签页对应于一个布局(从线性布局、框架布局、相对布局、表格布局中任选3个)实现下图界面。
说明:
所建的三个标签页分别使用:
线性布局(TAB1)、相对布局(TAB2)、表格布局(TAB3),实验截图分别为:
图1,图2,图3。
实验截图:
图1
图2
图3
2.使用TabHost(Tab标签页)建立3个标签页,各标签页控件内容如下:
1.分页1标题为“多选及单选演示”,含有一个TextView控件,3个CheckBox控件和1组(含4个)RadioButton控件。
TextView控件用于显示用户点击某控件后的结果。
实验截图:
如图4所示
图4
2.分页2标题为“Spinner演示”,含有2个Spinner控件,一个Spinner用于选择年级(大一~大四),另一个用于选择性别。
实验截图:
如图5、6所示
图5
图6
3.分页3标题为“ListView演示”,含有一个ListView控件(拥有10个子项),一个TextView控件用于显示用户点击某子项后的结果
实验截图:
如图7所示
图7
3.在第1题的按钮栏下面添加一个TextView控件用于显示数据,然后实现“添加数据”、“全部显示”、“清除显示”和“全部删除”4个按钮的功能。
说明:
本操作需要操作数据库,目前暂未开发),仅实现的是将所输入的数据显示到下面的TextView里面(如图8所示)。
图8
4.实现第2题中各个控件的点击响应功能,响应结果显示在所在页的TextView控件中。
实验截图:
如图9,10,11所示
图9
图10
图11
核心代码
1、3题:
activity_main_activity207.xml:
xmlversion="1.0"encoding="utf-8"?
>
android=" android: id="@android: id/tabhost" android: layout_width="fill_parent" android: layout_height="fill_parent"> android: orientation="vertical" android: layout_width="fill_parent" android: layout_height="fill_parent"> android: id="@android: id/tabs" android: layout_width="fill_parent" android: layout_height="wrap_content"/> android: id="@android: id/tabcontent" android: layout_width="fill_parent" android: layout_height="fill_parent"/> activity_tab1_activity207.xml: xmlversion="1.0"encoding="utf-8"? > android=" android: orientation="vertical" android: layout_width="fill_parent" android: layout_height="wrap_content"> android: orientation="horizontal" android: layout_width="wrap_content" android: layout_height="wrap_content" android: padding="10dp"> id="@+id/nameText" android: layout_width="fill_parent" android: layout_height="wrap_content" android: text="@string/nameText"> id="@+id/nameEdit" android: inputType="text" android: layout_width="wrap_content" android: layout_height="wrap_content"/> android: orientation="horizontal" android: layout_width="wrap_content" android: layout_height="wrap_content" android: padding="10dp"> id="@+id/ageText" android: layout_width="fill_parent" android: layout_height="wrap_content" android: text="@string/ageText"> id="@+id/ageEdit" android: inputType="text" android: layout_width="wrap_content" android: layout_height="wrap_content"/> android: orientation="horizontal" android: layout_width="wrap_content" android: layout_height="wrap_content" android: padding="10dip"> id="@+id/shengaoText" android: layout_width="fill_parent" android: layout_height="wrap_content" android: text="@string/shengaoText"> id="@+id/shengaoEdit" android: inputType="text" android: layout_width="wrap_content" android: layout_height="wrap_content"/> android: orientation="horizontal" android: layout_width="match_parent" android: layout_height="fill_parent" android: padding="5dip" android: paddingRight="5dip"> id="@+id/addButton" android: layout_width="70dip" android: layout_height="wrap_content" android: text="@string/addButton"/> id="@+id/showallButton" android: layout_width="70dip" android: layout_height="wrap_content" android: text="@string/showallButton"/> id="@+id/cleanButton" android: layout_width="70dip" android: layout_height="wrap_content" android: text="@string/cleanButton"/> id="@+id/deleteButton" android: layout_width="70dip" android: layout_height="wrap_content" android: text="@string/deleteButton"/> android: id="@+id/showAboutText" android: layout_width="wrap_content" android: layout_height="wrap_content" android: text="@string/showAbout"/> activity_tab2_activity207.xml: 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=".MainActivity207"> android: layout_width="match_parent" android: layout_height="match_parent" android: id="@+id/mainLayout2"> id="@+id/nameText" android: layout_width="wrap_content" android: layout_height="wrap_content" android: text="@string/nameText" android: layout_alignParentLeft="true" android: layout_marginTop="15dip"> id="@+id/nameEdit" android: layout_width="wrap_content" android: layout_height="wrap_content" android: layout_toRightOf="@+id/nameText" android: layout_alignBottom="@+id/nameText"> id="@+id/ageText" android: layout_width="wrap_content" android: layout_height="wrap_content" android: layout_below="@+id/nameText" android: text="@string/ageText" android: layout_alignParentLeft="true" android: layout_marginTop="15dip"> id="@+id/ageEdit" android: layout_width="wrap_content" android: layout_height="wrap_content" android: layout_toRightOf="@+id/ageText" android: layout_alignBottom="@+id/ageText"> id="@+id/shengaoText" android: layout_width="wrap_content" android: layout_height="wrap_content" android: layout_below="@+id/ageText" android: text="@string/shengaoText" android: layout_alignParentLeft="true" android: layout_marginTop="15dip"> id="@+id/shengaoEdit" android: layout_width="wrap_content" android: layout_height="wrap_content" android: layout_toRightOf="@+id/shengaoText" android: layout_alignBottom="@+id/shengaoText"> android: id="@+id/Buttons" android: layout_width="fill_parent" android: layout_height="match_parent" android: layout_below="@+id/shengaoText" android: paddingLeft="5dip"> id="@+id/addButton" android: layout_width="70dip" android: layout_height="wrap_content" android: text="@string/addButton"/> id="@+id/showallButton" android: layout_width="70dip" android: layout_height="wrap_content" android: text="@string/showallButton" android: layout_toRightOf="@+id/addButton"/> id="@+id/cleanButton" android: layout_width="70dip" android: layout_height="wrap_content" android: text="@string/cleanButton" android: layout_toRightOf="@+id/showallButton"/> id="@+id/deleteButton" android: layout_width="70dip" android: layout_height="wrap_content" android: text="@string/deleteButton" android: layout_toRightOf="@+id/cleanButton"/> android: id="@+id/showAbout" android: layout_width="fill_parent" android: layout_height="wrap_content" android: layout_below="@+id/Buttons" android: paddingLeft="5dip"> android: id="@+id/showAboutText" android: layout_width="wrap_content" android: layout_height="wrap_content" android: text="@string/showAbout"/> activity_tab3_activity207.xml: 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=".MainActivity207"> android: layout_width="match_parent" android: layout_height="match_parent" android: id="@+id/mainLayout3" android: shrinkColumns="1"> id="@+id/tableRow1" android: layout_width="wrap_content" android: layout_height="wrap_content"> android: collapseColumns='0' android: id="@+id/nameText" android: layout_width="fill_parent" android: layout_height="wrap_content" android: text="@string/nameText"> id="@+id/nameEdit" android: layout_width="fill_parent" android: layout_height="wrap_content"> id="@+id/tableRow2" android: layout_width="wrap_content" android: layout_height="wrap_content"> id="@+id/ageText" android: layout_width="fill_parent" android: layout_height="wrap_content" android: text="@string/ageText"> id="@+id/ageEdit" android: layout_width="fill_parent" android: layout_height="wrap_content"> id="@+id/tableRow3" android: layout_width="wrap_content" android: layout_height="wrap_content"> id="@+id/shengaoText" android: layout_width="fill_parent" android: layout_height="wrap_content" android: text="@string/shengaoText"> id="@+id/shengaoEdit" android: layout_width="fill_parent" android: layout_height="wrap_content"> id="@+id/tableRow4" android: layout_width="wrap_content" android: layout_height="wrap_content"> id="@+id/addButton" android: layout_width="70dip" android: layout_height="wrap_content" android: text="@string/addButton" android: shrinkColumns="true"/>
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Android 基础 开发 练习