(一)

知识点: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. 获取oracle当前系统设置了哪些事件

    ALTER SESSION SET EVENTS '10046 trace name context forever,level 12' 会话已更改. DECLARE EVENT_LEVEL NUMB ...

  2. fscanf函数的应用

    转摘自:http://blog.csdn.net/mxgsgtc/article/details/13005675 以前老是被从文本里读取文件,然后逐个的进行字符解析,感觉非常的慢,自从知道了fsca ...

  3. 有关getClassLoader().getResourceAsStream(fileName)、class.getResourceAsStream(fileName)和().getContextClassLoader().getResourceAsStream(fileName)的区别

    一:前言 在自己获取属性时,碰见了XX.class.getResourceAsStream(fileName),自己对这个其实不是很理解,上网查了下资料,又看到了上述的几个,所以就研究了下. 二:内容 ...

  4. 51Nod 1421

    1421 最大MOD值 有一个a数组,里面有n个整数.现在要从中找到两个数字(可以是同一个) ai,aj ,使得 ai mod aj 最大并且 ai ≥ aj. Input 单组测试数据. 第一行包含 ...

  5. 图论:费用流-SPFA+EK

    利用SPFA+EK算法解决费用流问题 例题不够裸,但是还是很有说服力的,这里以Codevs1227的方格取数2为例子来介绍费用流问题 这个题难点在建图上,我感觉以后还要把网络流建模想明白才能下手去做这 ...

  6. vivo面试学习1(io和nio)

    一.io流(一次从open到底层的操作) 输入和输出流 IO流 字节流 Reader.Writer 字符流 InputStream.OutputStream 字节流:可以处理所有bit为单位存储的文件 ...

  7. Atos cannot get symbols from dSYM of archived application

    http://stackoverflow.com/questions/7675863/atos-cannot-get-symbols-from-dsym-of-archived-application ...

  8. UVALIVE 4330 Timer

    Description   Recently, some archaeologists discovered an ancient relic on a small island in the Pac ...

  9. APMserv常见问题

    一.启动是提示apache启动失败,mysql启动成功 1.去掉ssl的勾选(勾选需要证书),重启看解决没有 2.端口被占,吧apache端口改成80或者8080端口(其他端口也可以试试,80的话访问 ...

  10. 记录一次lnmp故障报告

    业务架构图: nginx 状态监控图: 本次故障的表现为:前端php页面无法打开,空白页或者502错误. nginx中php配置如下: location ~ \.php$ { root /xxx/xx ...