(一)

知识点:id使用系统自带

1.效果图:

2.布局

activity_main.xml

 <?xml version="1.0" encoding="utf-8"?>
<TabHost
android:id="@android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!--选项卡标题表-->
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"></TabWidget>
<!--选项卡布局-->
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent"></FrameLayout>
</LinearLayout> </TabHost>

也可以在  activity_main.xml布局中使用include

tab1.xml

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/tab01">
<TextView
android:text="LinnerLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content" /> </LinearLayout>

tab2.xml

 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tab02">
<TextView
android:text="RelativeLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</RelativeLayout>

tab3.xml

 <?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tab03">
<TextView
android:text="AbsoluteLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</AbsoluteLayout>

2.MainActivity.java

 package com.example.administrator.hello2;

 import android.app.TabActivity;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.widget.TabHost; public class MainActivity extends TabActivity { private TabHost tabHost;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); tabHost = getTabHost(); LayoutInflater.from(MainActivity.this).inflate(R.layout.tab1,tabHost.getTabContentView(),true);
LayoutInflater.from(MainActivity.this).inflate(R.layout.tab2,tabHost.getTabContentView(),true);
LayoutInflater.from(MainActivity.this).inflate(R.layout.tab3,tabHost.getTabContentView(),true); tabHost.addTab(tabHost.newTabSpec("TAB1").setIndicator("线性布局").setContent(R.id.tab01));
tabHost.addTab(tabHost.newTabSpec("TAB1").setIndicator("相对布局").setContent(R.id.tab02));
tabHost.addTab(tabHost.newTabSpec("TAB1").setIndicator("绝对布局").setContent(R.id.tab03)); }
}

TabHost的更多相关文章

  1. android 使用Tabhost 发生could not create tab content because could not find view with id 错误

    使用Tabhost的时候经常报:could not create tab content because could not find view with id 错误. 总结一下发生错误的原因,一般的 ...

  2. Android 轮换页面+TabHost 实例

    最终效果展示: 首先我们需要一个ViewPager控件,不过可以发现在左侧的控件列表中并没有这个控件 这时我们要去升级包中查看 然后在厘米找到 ViewPager.class 这时我们双击这个发现不能 ...

  3. tabhost 下 setOnItemClickListener失效的问题

    分析了一下代码,应该是tabhost 的ontabchangedListener接管了下面应该由setOnItemClickListener接管的部分,导致不能相应setOnItemClickList ...

  4. 安卓初級教程(5):TabHost的思考

    package com.myhost; import android.os.Bundle; import android.view.LayoutInflater; import android.wid ...

  5. Android 实现分页(使用TabWidget/TabHost)

    注:本文为转载,但该内容本人已亲身尝试,确认该方法可行,代码有点小的改动,转载用作保存与分享. 原作者地址:http://gundumw100.iteye.com/blog/853967 个人吐嘈:据 ...

  6. 安卓TabHost页面

    <?xml version="1.0" encoding="UTF-8"?> <!-- TabHost组件id值不可变--> <T ...

  7. Android TabHost使用

    TabHost是Android中自带的选项卡控件,效果图如下: 主布局文件 <RelativeLayout xmlns:android="http://schemas.android. ...

  8. tabhost使用

    Tabhost用法 使用方法一:使用同一个布局文件 在xml中如此定义tabhost: <RelativeLayout xmlns:android="http://schemas.an ...

  9. tab使用 TabActivity TabHost Tabspec常用方法

    本文是参考Android官方提供的sample里面的ApiDemos的学习总结.   TabActivity   首先Android里面有个名为TabActivity来给我们方便使用.其中有以下可以关 ...

  10. Android工作学习第5天之TabHost实现菜单栏底部显示

    TabHost是一个装载选项卡窗口的容器,实现分模块显示的效果.像新浪微博客户端.微信客户端都是使用tabehost组件来开发的. TabHost的组成: |---TabWidget:实现标签栏,可供 ...

随机推荐

  1. SQL 学习小笔记

    1.FOUND_ROWS() 题目: ,; 在上边sql中使用什么选项可以使 SELECT FOUND_ROWS()忽略LIMIT子句,返回总数? *答案* : SQL_CALC_FOUND_ROWS ...

  2. 转:增强学习(二)----- 马尔可夫决策过程MDP

    1. 马尔可夫模型的几类子模型 大家应该还记得马尔科夫链(Markov Chain),了解机器学习的也都知道隐马尔可夫模型(Hidden Markov Model,HMM).它们具有的一个共同性质就是 ...

  3. [bzoj1251]序列终结者——splay

    题目大意 网上有许多题,就是给定一个序列,要你支持几种操作:A.B.C.D.一看另一道题,又是一个序列 要支持几种操作:D.C.B.A.尤其是我们这里的某人,出模拟试题,居然还出了一道这样的,真是没技 ...

  4. python3 迭代器,生成器

    一 .什么是迭代 1. 重复 2.下次重复一定是基于上一次的结果而来 while True: cmd=input(':') print(cmd) l=[1,2,3,4] count=0 while c ...

  5. POJ1080(LCS变形)

    Human Gene Functions Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Oth ...

  6. appium的使用

    这套教程年久失修,问题的人也比较多,于是,我重新整理了一套appium入门教程. appium新手入门(1)—— appium介绍 appium新手入门(2)—— 安装 Android SDK app ...

  7. php性能调试工具介绍

    php版本:php7 xhprof: xhprof是php5.*下很好的性能测试工具,配合xhprof_html能够图形显示测试结果,基本够用, 但已经没人维护了. tideways: 在php7下, ...

  8. ZOJ-3822

    Domination Time Limit: 8 Seconds      Memory Limit: 131072 KB      Special Judge Edward is the headm ...

  9. hdu 5171(矩阵快速幂,递推)

    GTY's birthday gift Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Othe ...

  10. PO/POJO/BO/DTO/VO的区别(转)

    PO :persistent object持久对象 1 .有时也被称为Data对象,对应数据库中的entity,可以简单认为一个PO对应数据库中的一条记录. 2 .在hibernate持久化框架中与i ...