Android 创建Tab

本文详细介绍使用Android的TabActivity创建Tab导航界面的过程。包括创建Tabhost、TabSpec,设置指示符与内容,并将TabSpec添加到Tabhost中。同时提供了一个具体的实现案例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

先来一张图展示一下Tab。

在创建Tab之前,先把Tab的结构搞清楚。它的结构是这样的:

最外层是一个Tabhost,Tabhost里装了些选项卡(TabSpec),每个选项卡有自己的指示符(Indicator,就是顶部可点的那个区块)和内容(Content,下半部分展示内容的区块)。

现在,要做的事情就很清楚了:

1、创建Tabhost

2、创建TabSpec并给TabSpec赋值

3、把TabSpec添加到Tabhost中

那问题又接着来了。

1、如何创建Tabhost?

Android为我们提供了TabActivity,我们只要继承它,就可以得到Tabhost了。看代码:

public class HomeActivity extends TabActivity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //获取Tabhost TabHost tabhost = this.getTabHost(); }

2、如何创建TabSpec,如何赋值?

我们得到tabhost之后,通过它我们就可以创建新的选项卡,看代码:

// 选项卡的内容先在main文件中写好,当然你不用非得写在main里的。xml文件内容具体在后面给出。 // 这里相当于把Tab要用到的布局与Tabhost绑定起来。 LayoutInflater.from(this).inflate(R.layout.main, tabhost.getTabContentView() ,true); // 此处tab1相当于是选项卡的名字 TabSpec tabSpec1 = tabhost.newTabSpec("tab1"); TabSpec tabSpec2 = tabhost.newTabSpec("tab2"); TabSpec tabSpec3 = tabhost.newTabSpec("tab3"); // 设置选项卡头部的信息,也可以给他设置图片,只需要用setIndicator的重载方法即可 tabSpec1.setIndicator("首页"); tabSpec2.setIndicator("吼吼"); tabSpec3.setIndicator("私信"); // 设置选项卡的内容,共有三种方法,以下是api中的原文 // 1) the id of a View // 2) a TabHost.TabContentFactory that creates the View content. // 3) an Intent that launches an Activity // 此处用的是第一种方法,即先在xml中布局好再到这里来设置。 tabSpec1.setContent(R.id.tab1); tabSpec2.setContent(R.id.tab2); tabSpec3.setContent(R.id.tab3);

3、如何添加?

这最非常容易了,看代码:

tabhost.addTab(tabSpec1); tabhost.addTab(tabSpec2); tabhost.addTab(tabSpec3);

最后还要加上一句

setContentView(tabhost);

这就差不多了。

来看看main.xml里的内容。注意每个LinearLayout通过Id与选项卡绑定。

<?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" > <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/tab1" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> </LinearLayout> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/tab2" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> </LinearLayout> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/tab3" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:id="@+id/username" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> </LinearLayout> </FrameLayout>




内容概要:本文档定义了一个名为 `xxx_SCustSuplier_info` 的视图,用于整合和展示客户(Customer)和供应商(Supplier)的相关信息。视图通过连接多个表来获取组织单位、客户账户、站点使用、位置、财务代码组合等数据。对于客户部分,视图选择了与账单相关的记录,并提取了账单客户ID、账单站点ID、客户名称、账户名称、站点代码、状态、付款条款等信息;对于供应商部分,视图选择了有效的供应商及其站点信息,包括供应商ID、供应商名称、供应商编号、状态、付款条款、财务代码组合等。视图还通过外连接确保即使某些字段为空也能显示相关信息。 适合人群:熟悉Oracle ERP系统,尤其是应付账款(AP)和应收账款(AR)模块的数据库管理员或开发人员;需要查询和管理客户及供应商信息的业务分析师。 使用场景及目标:① 数据库管理员可以通过此视图快速查询客户和供应商的基本信息,包括账单信息、财务代码组合等;② 开发人员可以利用此视图进行报表开发或数据迁移;③ 业务分析师可以使用此视图进行数据分析,如信用评估、付款周期分析等。 阅读建议:由于该视图涉及多个表的复杂连接,建议读者先熟悉各个表的结构和关系,特别是 `hz_parties`、`hz_cust_accounts`、`ap_suppliers` 等核心表。此外,注意视图中使用的外连接(如 `gl_code_combinations_kfv` 表的连接),这可能会影响查询结果的完整性。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值