南昌航空大学android期末复习资料之编程题.docx
《南昌航空大学android期末复习资料之编程题.docx》由会员分享,可在线阅读,更多相关《南昌航空大学android期末复习资料之编程题.docx(27页珍藏版)》请在冰豆网上搜索。
南昌航空大学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.xmlxmlversion="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.xmlxmlversion="1.0"encoding="utf-8"?>姓名:年龄:身高:添加数据全部显示清除显示全部清除king301.75RelativeLayout绝对布局main.xmlxmlversion="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.javapublicclassTabDemoextendsTabActivity{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.xmlxmlversion="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.javapublicclassListViewDemoextendsActivity{/**Calledwhentheactivityisfirstcreated.*/@OverridepublicvoidonCreate(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(){@OverridepublicvoidonItemClick(AdapterView>arg0,Viewarg1,intarg2,longarg3){Stringmsg="父View:"+arg0.toString()+"\n
android="
android:
orientation="vertical"
layout_width="fill_parent"
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"/>
layout_height="wrap_content"
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"/>
id="@+id/NameText"
layout_width="wrap_content"
text="姓名:
"/>
android:id="@+id/Name"android:layout_width="fill_parent"android:layout_height="wrap_content"android:text="king"/>
id="@+id/Name"
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: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"/>
id="@+id/AgeText"
text="年龄:
android:id="@+id/UserText"android:layout_width="fill_parent"android:layout_height="wrap_content"android:text="30"/>
id="@+id/UserText"
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: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"/>
id="@+id/HeightText"
text="身高:
android:id="@+id/Height"android:layout_width="fill_parent"android:layout_height="wrap_content"android:text="1.75"/>
id="@+id/Height"
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="全部删除"/>
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="全部删除"/>
id="@+id/Button1"
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="全部删除"/>
id="@+id/Button2"
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="全部删除"/>
id="@+id/Button3"
text="清除显示"/>
android:id="@+id/Button4"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="全部删除"/>
id="@+id/Button4"
text="全部删除"/>
相对布局
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.xmlxmlversion="1.0"encoding="utf-8"?>姓名:年龄:身高:添加数据全部显示清除显示全部清除king301.75RelativeLayout绝对布局main.xmlxmlversion="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.javapublicclassTabDemoextendsTabActivity{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.xmlxmlversion="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.javapublicclassListViewDemoextendsActivity{/**Calledwhentheactivityisfirstcreated.*/@OverridepublicvoidonCreate(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(){@OverridepublicvoidonItemClick(AdapterView>arg0,Viewarg1,intarg2,longarg3){Stringmsg="父View:"+arg0.toString()+"\n
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.xmlxmlversion="1.0"encoding="utf-8"?>姓名:年龄:身高:添加数据全部显示清除显示全部清除king301.75RelativeLayout绝对布局main.xmlxmlversion="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.javapublicclassTabDemoextendsTabActivity{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.xmlxmlversion="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.javapublicclassListViewDemoextendsActivity{/**Calledwhentheactivityisfirstcreated.*/@OverridepublicvoidonCreate(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(){@OverridepublicvoidonItemClick(AdapterView>arg0,Viewarg1,intarg2,longarg3){Stringmsg="父View:"+arg0.toString()+"\n
text="@string/nametext"
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.xmlxmlversion="1.0"encoding="utf-8"?>姓名:年龄:身高:添加数据全部显示清除显示全部清除king301.75RelativeLayout绝对布局main.xmlxmlversion="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.javapublicclassTabDemoextendsTabActivity{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.xmlxmlversion="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.javapublicclassListViewDemoextendsActivity{/**Calledwhentheactivityisfirstcreated.*/@OverridepublicvoidonCreate(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(){@OverridepublicvoidonItemClick(AdapterView>arg0,Viewarg1,intarg2,longarg3){Stringmsg="父View:"+arg0.toString()+"\n
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.xmlxmlversion="1.0"encoding="utf-8"?>姓名:年龄:身高:添加数据全部显示清除显示全部清除king301.75RelativeLayout绝对布局main.xmlxmlversion="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.javapublicclassTabDemoextendsTabActivity{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.xmlxmlversion="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.javapublicclassListViewDemoextendsActivity{/**Calledwhentheactivityisfirstcreated.*/@OverridepublicvoidonCreate(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(){@OverridepublicvoidonItemClick(AdapterView>arg0,Viewarg1,intarg2,longarg3){Stringmsg="父View:"+arg0.toString()+"\n
text="@string/agetext"
layout_marginTop="30dip"
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.xmlxmlversion="1.0"encoding="utf-8"?>姓名:年龄:身高:添加数据全部显示清除显示全部清除king301.75RelativeLayout绝对布局main.xmlxmlversion="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.javapublicclassTabDemoextendsTabActivity{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.xmlxmlversion="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.javapublicclassListViewDemoextendsActivity{/**Calledwhentheactivityisfirstcreated.*/@OverridepublicvoidonCreate(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(){@OverridepublicvoidonItemClick(AdapterView>arg0,Viewarg1,intarg2,longarg3){Stringmsg="父View:"+arg0.toString()+"\n
id="@+id/Age"
layout_below="@id/Name"
layout_toRightOf="@id/AgeText"
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.xmlxmlversion="1.0"encoding="utf-8"?>姓名:年龄:身高:添加数据全部显示清除显示全部清除king301.75RelativeLayout绝对布局main.xmlxmlversion="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.javapublicclassTabDemoextendsTabActivity{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.xmlxmlversion="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.javapublicclassListViewDemoextendsActivity{/**Calledwhentheactivityisfirstcreated.*/@OverridepublicvoidonCreate(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(){@OverridepublicvoidonItemClick(AdapterView>arg0,Viewarg1,intarg2,longarg3){Stringmsg="父View:"+arg0.toString()+"\n
text="@string/heighttext"
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.xmlxmlversion="1.0"encoding="utf-8"?>姓名:年龄:身高:添加数据全部显示清除显示全部清除king301.75RelativeLayout绝对布局main.xmlxmlversion="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.javapublicclassTabDemoextendsTabActivity{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.xmlxmlversion="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.javapublicclassListViewDemoextendsActivity{/**Calledwhentheactivityisfirstcreated.*/@OverridepublicvoidonCreate(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(){@OverridepublicvoidonItemClick(AdapterView>arg0,Viewarg1,intarg2,longarg3){Stringmsg="父View:"+arg0.toString()+"\n
layout_below="@id/Age"
layout_toRightOf="@id/HeightText"
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.xmlxmlversion="1.0"encoding="utf-8"?>姓名:年龄:身高:添加数据全部显示清除显示全部清除king301.75RelativeLayout绝对布局main.xmlxmlversion="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.javapublicclassTabDemoextendsTabActivity{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.xmlxmlversion="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.javapublicclassListViewDemoextendsActivity{/**Calledwhentheactivityisfirstcreated.*/@OverridepublicvoidonCreate(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(){@OverridepublicvoidonItemClick(AdapterView>arg0,Viewarg1,intarg2,longarg3){Stringmsg="父View:"+arg0.toString()+"\n
layout_below="@id/Height"
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.xmlxmlversion="1.0"encoding="utf-8"?>姓名:年龄:身高:添加数据全部显示清除显示全部清除king301.75RelativeLayout绝对布局main.xmlxmlversion="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.javapublicclassTabDemoextendsTabActivity{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.xmlxmlversion="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.javapublicclassListViewDemoextendsActivity{/**Calledwhentheactivityisfirstcreated.*/@OverridepublicvoidonCreate(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(){@OverridepublicvoidonItemClick(AdapterView>arg0,Viewarg1,intarg2,longarg3){Stringmsg="父View:"+arg0.toString()+"\n
layout_toRightOf="@id/Button1"
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.xmlxmlversion="1.0"encoding="utf-8"?>姓名:年龄:身高:添加数据全部显示清除显示全部清除king301.75RelativeLayout绝对布局main.xmlxmlversion="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.javapublicclassTabDemoextendsTabActivity{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.xmlxmlversion="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.javapublicclassListViewDemoextendsActivity{/**Calledwhentheactivityisfirstcreated.*/@OverridepublicvoidonCreate(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(){@OverridepublicvoidonItemClick(AdapterView>arg0,Viewarg1,intarg2,longarg3){Stringmsg="父View:"+arg0.toString()+"\n
layout_toRightOf="@id/Button2"
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.xmlxmlversion="1.0"encoding="utf-8"?>姓名:年龄:身高:添加数据全部显示清除显示全部清除king301.75RelativeLayout绝对布局main.xmlxmlversion="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.javapublicclassTabDemoextendsTabActivity{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.xmlxmlversion="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.javapublicclassListViewDemoextendsActivity{/**Calledwhentheactivityisfirstcreated.*/@OverridepublicvoidonCreate(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(){@OverridepublicvoidonItemClick(AdapterView>arg0,Viewarg1,intarg2,longarg3){Stringmsg="父View:"+arg0.toString()+"\n
layout_toRightOf="@id/Button3"
text="@string/buttontext4"/>
String.xml
姓名:
年龄:
身高:
添加数据
全部显示
清除显示
全部清除
king
30
1.75
RelativeLayout
绝对布局
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.javapublicclassTabDemoextendsTabActivity{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.xmlxmlversion="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.javapublicclassListViewDemoextendsActivity{/**Calledwhentheactivityisfirstcreated.*/@OverridepublicvoidonCreate(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(){@OverridepublicvoidonItemClick(AdapterView>arg0,Viewarg1,intarg2,longarg3){Stringmsg="父View:"+arg0.toString()+"\n
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.javapublicclassTabDemoextendsTabActivity{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.xmlxmlversion="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.javapublicclassListViewDemoextendsActivity{/**Calledwhentheactivityisfirstcreated.*/@OverridepublicvoidonCreate(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(){@OverridepublicvoidonItemClick(AdapterView>arg0,Viewarg1,intarg2,longarg3){Stringmsg="父View:"+arg0.toString()+"\n
"
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.javapublicclassTabDemoextendsTabActivity{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.xmlxmlversion="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.javapublicclassListViewDemoextendsActivity{/**Calledwhentheactivityisfirstcreated.*/@OverridepublicvoidonCreate(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(){@OverridepublicvoidonItemClick(AdapterView>arg0,Viewarg1,intarg2,longarg3){Stringmsg="父View:"+arg0.toString()+"\n
layout_width="280dip"
layout_height="50dip"
layout_x="40dip"
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.javapublicclassTabDemoextendsTabActivity{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.xmlxmlversion="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.javapublicclassListViewDemoextendsActivity{/**Calledwhentheactivityisfirstcreated.*/@OverridepublicvoidonCreate(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(){@OverridepublicvoidonItemClick(AdapterView>arg0,Viewarg1,intarg2,longarg3){Stringmsg="父View:"+arg0.toString()+"\n
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.javapublicclassTabDemoextendsTabActivity{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.xmlxmlversion="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.javapublicclassListViewDemoextendsActivity{/**Calledwhentheactivityisfirstcreated.*/@OverridepublicvoidonCreate(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(){@OverridepublicvoidonItemClick(AdapterView>arg0,Viewarg1,intarg2,longarg3){Stringmsg="父View:"+arg0.toString()+"\n
layout_y="50dip"
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.javapublicclassTabDemoextendsTabActivity{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.xmlxmlversion="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.javapublicclassListViewDemoextendsActivity{/**Calledwhentheactivityisfirstcreated.*/@OverridepublicvoidonCreate(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(){@OverridepublicvoidonItemClick(AdapterView>arg0,Viewarg1,intarg2,longarg3){Stringmsg="父View:"+arg0.toString()+"\n
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.javapublicclassTabDemoextendsTabActivity{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.xmlxmlversion="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.javapublicclassListViewDemoextendsActivity{/**Calledwhentheactivityisfirstcreated.*/@OverridepublicvoidonCreate(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(){@OverridepublicvoidonItemClick(AdapterView>arg0,Viewarg1,intarg2,longarg3){Stringmsg="父View:"+arg0.toString()+"\n
layout_y="100dip"
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.javapublicclassTabDemoextendsTabActivity{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.xmlxmlversion="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.javapublicclassListViewDemoextendsActivity{/**Calledwhentheactivityisfirstcreated.*/@OverridepublicvoidonCreate(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(){@OverridepublicvoidonItemClick(AdapterView>arg0,Viewarg1,intarg2,longarg3){Stringmsg="父View:"+arg0.toString()+"\n
layout_y="160dip"
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.javapublicclassTabDemoextendsTabActivity{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.xmlxmlversion="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.javapublicclassListViewDemoextendsActivity{/**Calledwhentheactivityisfirstcreated.*/@OverridepublicvoidonCreate(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(){@OverridepublicvoidonItemClick(AdapterView>arg0,Viewarg1,intarg2,longarg3){Stringmsg="父View:"+arg0.toString()+"\n
layout_x="80dip"
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.javapublicclassTabDemoextendsTabActivity{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.xmlxmlversion="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.javapublicclassListViewDemoextendsActivity{/**Calledwhentheactivityisfirstcreated.*/@OverridepublicvoidonCreate(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(){@OverridepublicvoidonItemClick(AdapterView>arg0,Viewarg1,intarg2,longarg3){Stringmsg="父View:"+arg0.toString()+"\n
layout_x="160dip"
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.javapublicclassTabDemoextendsTabActivity{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.xmlxmlversion="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.javapublicclassListViewDemoextendsActivity{/**Calledwhentheactivityisfirstcreated.*/@OverridepublicvoidonCreate(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(){@OverridepublicvoidonItemClick(AdapterView>arg0,Viewarg1,intarg2,longarg3){Stringmsg="父View:"+arg0.toString()+"\n
layout_x="240dip"
如果在这个基础上加上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(线性)
android="android:id="@+id/layout01"ListView的使用Main.xmlxmlversion="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.javapublicclassListViewDemoextendsActivity{/**Calledwhentheactivityisfirstcreated.*/@OverridepublicvoidonCreate(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(){@OverridepublicvoidonItemClick(AdapterView>arg0,Viewarg1,intarg2,longarg3){Stringmsg="父View:"+arg0.toString()+"\n
id="@+id/layout01"
ListView的使用
Main.xml
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.javapublicclassListViewDemoextendsActivity{/**Calledwhentheactivityisfirstcreated.*/@OverridepublicvoidonCreate(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(){@OverridepublicvoidonItemClick(AdapterView>arg0,Viewarg1,intarg2,longarg3){Stringmsg="父View:"+arg0.toString()+"\n
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.javapublicclassListViewDemoextendsActivity{/**Calledwhentheactivityisfirstcreated.*/@OverridepublicvoidonCreate(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(){@OverridepublicvoidonItemClick(AdapterView>arg0,Viewarg1,intarg2,longarg3){Stringmsg="父View:"+arg0.toString()+"\n
id="@+id/TextView01"
text="@string/hello"/>
id="@+id/ListView01"android:layout_width="wrap_content"android:layout_height="wrap_content">ListViewDemo.javapublicclassListViewDemoextendsActivity{/**Calledwhentheactivityisfirstcreated.*/@OverridepublicvoidonCreate(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(){@OverridepublicvoidonItemClick(AdapterView>arg0,Viewarg1,intarg2,longarg3){Stringmsg="父View:"+arg0.toString()+"\n
id="@+id/ListView01"
layout_height="wrap_content">
ListViewDemo.java
publicclassListViewDemoextendsActivity{
/**Calledwhentheactivityisfirstcreated.*/
@Override
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(){
publicvoidonItemClick(AdapterView
>arg0,Viewarg1,intarg2,longarg3){
Stringmsg="父View:
"+arg0.toString()+"\n
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1