Tabhost的简单使用
来源:互联网 发布:mac地址修改器手机版 编辑:程序博客网 时间:2024/06/12 01:37
建立主布局文件:
//其中红色为必选项,且注意id的写法
<?xml version="1.0"encoding="utf-8"?>
<RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TabHost
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/TabHost1">
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="wrap_content">
<TabWidget
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@android:id/tabs">
</TabWidget>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@android:id/tabcontent">
</FrameLayout>
</LinearLayout>
</TabHost>
<RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TabHost
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/TabHost1">
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="wrap_content">
<TabWidget
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@android:id/tabs">
</TabWidget>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@android:id/tabcontent">
</FrameLayout>
</LinearLayout>
</TabHost>
</RelativeLayout >
//设置标签页布局,注意红色和蓝色的标记
标签页布局1:tab1_layout
<LinearLayoutandroid:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/tabLinLayout1"
xmlns:android="http://schemas.android.com/apk/res/android">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/btnBack"
android:text="返回"/>
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/tabLinLayout1"
xmlns:android="http://schemas.android.com/apk/res/android">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/btnBack"
android:text="返回"/>
</LinearLayout>
标签页布局2:tab2_layout
<?xml version="1.0"encoding="utf-8"?>
<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/tabLinLayout2">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/btn2Back"
android:text="back"/>
<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/tabLinLayout2">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/btn2Back"
android:text="back"/>
</LinearLayout>
在java代码中的使用:
TabHost tabHost = (TabHost) findViewById(R.id.TabHost1);
tabHost.setup(); //启用
//声明布局文件,通过选取布局文件名方式
LayoutInflater layoutInflater = LayoutInflater.from(this);
layoutInflater.inflate(R.layout.tab1_layout,tabHost.getTabContentView());
layoutInflater.inflate(R.layout.tab2_layout,tabHost.getTabContentView());
//为布局设置id,配置标签时用id与标签绑定
tabHost.addTab(tabHost.newTabSpec("tab1").
setIndicator("标签1").setContent(R.id.tabLinLayout1));
tabHost.addTab(tabHost.newTabSpec("tab2").
tabHost.setup(); //启用
//声明布局文件,通过选取布局文件名方式
LayoutInflater layoutInflater = LayoutInflater.from(this);
layoutInflater.inflate(R.layout.tab1_layout,tabHost.getTabContentView());
layoutInflater.inflate(R.layout.tab2_layout,tabHost.getTabContentView());
//为布局设置id,配置标签时用id与标签绑定
tabHost.addTab(tabHost.newTabSpec("tab1").
setIndicator("标签1").setContent(R.id.tabLinLayout1));
tabHost.addTab(tabHost.newTabSpec("tab2").
setIndicator("标签2").setContent(R.id.tabLinLayout2));
1 0
- Tabhost的简单使用
- tabHost的简单使用
- Tabhost的简单使用
- TabHost空间的简单使用
- tabHost选项卡的简单使用
- TabHost简单使用
- TabHost简单使用示例
- <TabHost> 简单使用
- Andriod TabHost的使用TabHost
- tabhost简单使用及tabhost源码分析
- tabhost简单使用及tabhost源码分析
- 简单的TabHost
- Tabhost的简单运用
- Tabhost的简单用法
- TabHost的简单实用
- Android---61---TabHost简单使用
- Android TabHost的使用
- Android TabHost的使用
- onConfigurationChanged,oncreate 等
- 如何将Android Studio中的项目上传到GitHub中
- Android 摇一摇功能
- LeetCode66: Plus One
- BLE-NRF51822教程3-sdk程序框架剖析
- Tabhost的简单使用
- UILabel frame animate时文字跳跃异常
- SQL中的UNION和UNION ALL
- BLE-NRF51822教程4-串口BLE解析
- Mac 应用程序开发的绝佳起点
- Android自定义view+程序启动引导页面
- 支持向量机(四)
- BLE-NRF51822教程5-静态密码设置
- 软件测试---面试题汇总