TabHostProject 标签的使用(方法二 配置文件)
来源:互联网 发布:键盘打字指法软件 编辑:程序博客网 时间:2024/06/11 16:05
使用HostTab配置文件实现 较麻烦
Activity程序
public class MyTabHostDemo extends Activity {
private TabHost myTabHost = null;
private int[] layRes = new int[] { R.id.tab_edit, R.id.tab_clock,
R.id.tab_sex };
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.setContentView(R.layout.tab);
this.myTabHost =(TabHost) super.findViewById(R.id.myTabHost); // 取得TabHost对象
this.myTabHost.setup();
for(int x=0;x<this.layRes.length;x++){
TabSpec myTab=this.myTabHost.newTabSpec("tab"+x); //"tab"+x 所需的选项卡标签(tag)
myTab.setIndicator("标签-"+x); //设置每个子标签的名字
myTab.setContent(this.layRes[x]);
this.myTabHost.addTab(myTab);
}
this.myTabHost.setCurrentTab(1); //默认显示的标签
}
}
private TabHost myTabHost = null;
private int[] layRes = new int[] { R.id.tab_edit, R.id.tab_clock,
R.id.tab_sex };
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.setContentView(R.layout.tab);
this.myTabHost =(TabHost) super.findViewById(R.id.myTabHost); // 取得TabHost对象
this.myTabHost.setup();
for(int x=0;x<this.layRes.length;x++){
TabSpec myTab=this.myTabHost.newTabSpec("tab"+x); //"tab"+x 所需的选项卡标签(tag)
myTab.setIndicator("标签-"+x); //设置每个子标签的名字
myTab.setContent(this.layRes[x]);
this.myTabHost.addTab(myTab);
}
this.myTabHost.setCurrentTab(1); //默认显示的标签
}
配置文件Tab.xml
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/myTabHost"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="@+id/tab_edit"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<EditText
android:id="@+id/edit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="请输入搜索关键字。。。"
android:textSize="18px" />
<Button
android:id="@+id/myBut"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="搜索" />
</LinearLayout>
<LinearLayout
android:id="@+id/tab_clock"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<AnalogClock
android:id="@+id/myAnalogClock"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:id="@+id/tab_sex"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RadioGroup
android:id="@+id/sex"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<RadioButton
android:id="@+id/male"
android:checked="true"
android:text="性别:男" />
<RadioButton
android:id="@+id/female"
android:text="性别:女" />
</RadioGroup>
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/myTabHost"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="@+id/tab_edit"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<EditText
android:id="@+id/edit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="请输入搜索关键字。。。"
android:textSize="18px" />
<Button
android:id="@+id/myBut"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="搜索" />
</LinearLayout>
<LinearLayout
android:id="@+id/tab_clock"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<AnalogClock
android:id="@+id/myAnalogClock"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:id="@+id/tab_sex"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RadioGroup
android:id="@+id/sex"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<RadioButton
android:id="@+id/male"
android:checked="true"
android:text="性别:男" />
<RadioButton
android:id="@+id/female"
android:text="性别:女" />
</RadioGroup>
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
}
要使tab标签放在下方,只需要改两个地方,线性布局改成相对布局,TabWidgt中与容器底部对齐
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" />
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" />
0 0
- TabHostProject 标签的使用(方法二 配置文件)
- TabHostProject 标签的使用(方法一)
- 标签的使用(二)
- c#中配置文件的使用(二)
- RabbitMQ学习之spring配置文件rabbit标签的使用
- RabbitMQ学习之spring配置文件rabbit标签的使用
- RabbitMQ学习之spring配置文件rabbit标签的使用
- struts-标签的使用(二)
- Silverlight中使用配置文件的方法
- spring配置文件<import>标签中使用${}占位符获得配置文件的属性值
- spring配置文件<import>标签中使用${}占位符获得配置文件的属性值
- 常用的读取配置文件的方法(二)
- dwr如何配置多个配置文件的二种方法
- 自定义标签的两个配置文件
- Struts2的配置文件标签详解
- mybatis配置文件常用的标签
- mybatisXML配置文件的标签顺序
- HTML中使用struts标签的方法
- ZooKeeper伪分布式集群安装及使用
- 大公司好处
- 总结一些你肯定会用到的东西(长期更新)
- HD1001 sum--20140722
- Stanford 机器学习练习 Part 2 Logistics Regression
- TabHostProject 标签的使用(方法二 配置文件)
- hdu-2016-数据的交换输出习题解
- 如何部署应用到Oracle WebCenter Space
- HDOJ 3359 Kind of a Blur
- java实现二叉树层次遍历
- java对mongodb的操作
- 14 Annotation Junit 异常
- hdu1498 50 years, 50 colors --- 最小点覆盖
- linux i2c驱动开发