南昌航空大学android期末复习资料之编程题.docx

上传人:b****4 文档编号:4895628 上传时间:2022-12-11 格式:DOCX 页数:27 大小:118.31KB
下载 相关 举报
南昌航空大学android期末复习资料之编程题.docx_第1页
第1页 / 共27页
南昌航空大学android期末复习资料之编程题.docx_第2页
第2页 / 共27页
南昌航空大学android期末复习资料之编程题.docx_第3页
第3页 / 共27页
南昌航空大学android期末复习资料之编程题.docx_第4页
第4页 / 共27页
南昌航空大学android期末复习资料之编程题.docx_第5页
第5页 / 共27页
点击查看更多>>
下载资源
资源描述

南昌航空大学android期末复习资料之编程题.docx

《南昌航空大学android期末复习资料之编程题.docx》由会员分享,可在线阅读,更多相关《南昌航空大学android期末复习资料之编程题.docx(27页珍藏版)》请在冰豆网上搜索。

南昌航空大学android期末复习资料之编程题.docx

南昌航空大学android期末复习资料之编程题

参考下图中界面控件的摆放位置,分别使用线性布局、相对布局和绝对布局实现用户界面,并对比各种布局实现的复杂程度和对不同屏幕尺寸的适应能力。

线性布局:

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:

orientation="horizontal">

android:

id="@+id/NameText"

android:

layout_width="wrap_content"

android:

layout_height="wrap_content"

android:

text="姓名:

"/>

android:

id="@+id/Name"

android:

layout_width="fill_parent"

android:

layout_height="wrap_content"

android:

text="king"/>

android:

layout_width="fill_parent"

android:

layout_height="wrap_content"

android:

orientation="horizontal">

android:

id="@+id/AgeText"

android:

layout_width="wrap_content"

android:

layout_height="wrap_content"

android:

text="年龄:

"/>

android:

id="@+id/UserText"

android:

layout_width="fill_parent"

android:

layout_height="wrap_content"

android:

text="30"/>

android:

layout_width="fill_parent"

android:

layout_height="wrap_content"

android:

orientation="horizontal">

android:

id="@+id/HeightText"

android:

layout_width="wrap_content"

android:

layout_height="wrap_content"

android:

text="身高:

"/>

android:

id="@+id/Height"

android:

layout_width="fill_parent"

android:

layout_height="wrap_content"

android:

text="1.75"/>

android:

layout_width="fill_parent"

android:

layout_height="wrap_content"

android:

orientation="horizontal">

android:

id="@+id/Button1"

android:

layout_width="wrap_content"

android:

layout_height="wrap_content"

android:

text="添加数据"/>

android:

id="@+id/Button2"

android:

layout_width="wrap_content"

android:

layout_height="wrap_content"

android:

text="全部显示"/>

android:

id="@+id/Button3"

android:

layout_width="wrap_content"

android:

layout_height="wrap_content"

android:

text="清除显示"/>

android:

id="@+id/Button4"

android:

layout_width="wrap_content"

android:

layout_height="wrap_content"

android:

text="全部删除"/>

相对布局

main.xml

xmlversion="1.0"encoding="utf-8"?

>

android="

android:

layout_width="fill_parent"

android:

layout_height="fill_parent"

>

android:

id="@+id/NameText"

android:

layout_width="wrap_content"

android:

layout_height="wrap_content"

android:

text="@string/nametext"

android:

layout_marginTop="10dip"/>

android:

id="@+id/Name"

android:

layout_width="fill_parent"

android:

layout_height="wrap_content"

android:

layout_toRightOf="@id/NameText"

android:

id="@+id/AgeText"

android:

layout_width="wrap_content"

android:

layout_height="wrap_content"

android:

text="@string/agetext"

android:

layout_marginTop="30dip"

android:

layout_below="@id/NameText"/>

android:

id="@+id/Age"

android:

layout_width="fill_parent"

android:

layout_height="wrap_content"

android:

layout_below="@id/Name"

android:

layout_toRightOf="@id/AgeText"

android:

text="@string/edittext2"/>

android:

id="@+id/HeightText"

android:

layout_width="wrap_content"

android:

layout_height="wrap_content"

android:

text="@string/heighttext"

android:

layout_marginTop="30dip"

android:

layout_below="@id/AgeText"/>

android:

id="@+id/Height"

android:

layout_width="fill_parent"

android:

layout_height="wrap_content"

android:

layout_below="@id/Age"

android:

layout_toRightOf="@id/HeightText"

android:

text="@string/edittext3"/>

android:

id="@+id/Button1"

android:

layout_width="wrap_content"

android:

layout_height="wrap_content"

android:

layout_below="@id/Height"

android:

text="@string/buttontext1"/>

android:

id="@+id/Button2"

android:

layout_width="wrap_content"

android:

layout_height="wrap_content"

android:

layout_toRightOf="@id/Button1"

android:

layout_below="@id/Height"

android:

text="@string/buttontext2"/>

android:

id="@+id/Button3"

android:

layout_width="wrap_content"

android:

layout_height="wrap_content"

android:

layout_toRightOf="@id/Button2"

android:

layout_below="@id/Height"

android:

text="@string/buttontext3"/>

android:

id="@+id/Button4"

android:

layout_width="wrap_content"

android:

layout_height="wrap_content"

android:

layout_toRightOf="@id/Button3"

android:

layout_below="@id/Height"

android:

text="@string/buttontext4"/>

String.xml

xmlversion="1.0"encoding="utf-8"?

>

姓名:

年龄:

身高:

添加数据

全部显示

清除显示

全部清除

king

30

1.75

RelativeLayout

绝对布局

main.xml

xmlversion="1.0"encoding="utf-8"?

>

android="

android:

layout_width="fill_parent"

android:

layout_height="fill_parent">

android:

id="@+id/NameText"

android:

layout_width="wrap_content"

android:

layout_height="wrap_content"

android:

text="姓名:

"

android:

layout_y="10dip"/>

android:

id="@+id/Name"

android:

layout_width="280dip"

android:

layout_height="50dip"

android:

layout_x="40dip"

android:

text="king"/>

android:

id="@+id/AgeText"

android:

layout_width="wrap_content"

android:

layout_height="wrap_content"

android:

text="年龄:

"

android:

layout_y="60dip"/>

android:

id="@+id/Age"

android:

layout_width="280dip"

android:

layout_height="50dip"

android:

layout_x="40dip"

android:

layout_y="50dip"

android:

text="30"/>

android:

id="@+id/HeightText"

android:

layout_width="wrap_content"

android:

layout_height="wrap_content"

android:

text="身高:

"

android:

layout_y="110dip"/>

android:

id="@+id/Height"

android:

layout_width="280dip"

android:

layout_height="50dip"

android:

layout_x="40dip"

android:

layout_y="100dip"

android:

text="1.75"/>

android:

id="@+id/Button1"

android:

layout_width="wrap_content"

android:

layout_height="wrap_content"

android:

layout_y="160dip"

android:

text="添加数据"/>

android:

id="@+id/Button2"

android:

layout_width="wrap_content"

android:

layout_height="wrap_content"

android:

layout_x="80dip"

android:

layout_y="160dip"

android:

text="全部显示"/>

android:

id="@+id/Button3"

android:

layout_width="wrap_content"

android:

layout_height="wrap_content"

android:

layout_x="160dip"

android:

layout_y="160dip"

android:

text="清除显示"/>

android:

id="@+id/Button4"

android:

layout_width="wrap_content"

android:

layout_height="wrap_content"

android:

layout_x="240dip"

android:

layout_y="160dip"

android:

text="全部删除"/>

如果在这个基础上加上TabHost组件,如下图

TabDemo.java

publicclassTabDemoextendsTabActivity{

publicvoidonCreate(BundlesavedInstanceState){

super.onCreate(savedInstanceState);

TabHosttabHost=getTabHost();

LayoutInflater.from(this).inflate(R.layout.tab1,tabHost.getTabContentView(),true);

LayoutInflater.from(this).inflate(R.layout.tab2,tabHost.getTabContentView(),true);

LayoutInflater.from(this).inflate(R.layout.tab3,tabHost.getTabContentView(),true);

tabHost.addTab(tabHost.newTabSpec("TAB1").

setIndicator("线性布局").setContent(R.id.layout01));

tabHost.addTab(tabHost.newTabSpec("TAB2").

setIndicator("绝对布局").setContent(R.id.layout02));

tabHost.addTab(tabHost.newTabSpec("TAB3").

setIndicator("相对布局").setContent(R.id.layout03));

}

}

上面是java文件代码,这样还不行,要建立三个xml文件,分别为tab1.xml,tab2.xml,tab3.mxl,也就是上面三种布局的xml文件,不过要在每个xml文件的开头分别加上android:

id="@+id/layout01",android:

id="@+id/layout02",android:

id="@+id/layout03"

如:

tab1.xml(线性)

xmlversion="1.0"encoding="utf-8"?

>

android="

android:

id="@+id/layout01"

ListView的使用

Main.xml

xmlversion="1.0"encoding="utf-8"?

>

android="

android:

orientation="vertical"

android:

layout_width="fill_parent"

android:

layout_height="fill_parent"

>

id="@+id/TextView01"

android:

layout_width="fill_parent"

android:

layout_height="wrap_content"

android:

text="@string/hello"/>

id="@+id/ListView01"

android:

layout_width="wrap_content"

android:

layout_height="wrap_content">

ListViewDemo.java

publicclassListViewDemoextendsActivity{

/**Calledwhentheactivityisfirstcreated.*/

@Override

publicvoidonCreate(BundlesavedInstanceState){

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

finalTextViewtextView=(TextView)findViewById(R.id.TextView01);

ListViewlistView=(ListView)findViewById(R.id.ListView01);

Listlist=newArrayList();

list.add("ListView子项1");

list.add("ListView子项2");

list.add("ListView子项3");

ArrayAdapteradapter=newArrayAdapter(this,

android.R.layout.simple_list_item_1,list);

listView.setAdapter(adapter);

AdapterView.OnItemClickListenerlistViewListener=newAdapterView.OnItemClickListener(){

@Override

publicvoidonItemClick(AdapterView

>arg0,Viewarg1,intarg2,longarg3){

Stringmsg="父View:

"+arg0.toString()+"\n

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 工程科技 > 机械仪表

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1