Android -- TabHost

  TabHost 也就相当于Windows下的选项框

  有两种实现方式

      1.  继承TabActivity (已经废弃):从TabActivity中用getTabHost()方法获取TabHost

      2. 在布局文件中定义TabHost,但是TabWidget的id必须是@android:id/tabs,FrameLayout的id必须是@android:id/tabcontent.

   主要介绍第二种方法是的使用

    

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/hometabs"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TabHost
        android:id="@+id/tabhost"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        <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:orientation="horizontal" >
            </TabWidget>

            <FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" >

                <TextView
                    android:id="@+id/text"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:text="第一个选项框" />

                <TextView
                    android:id="@+id/photo"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:text="第二个选项框" />

                <TextView
                    android:id="@+id/video"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:text="第三个选项框" />
                   <TextView
                    android:id="@+id/movie"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:text="我是电影" />
            </FrameLayout>
        </LinearLayout>
    </TabHost>

</LinearLayout>

layout

时间: 2024-08-26 11:10:39

Android -- TabHost的相关文章

Android -- TabHost、Fragment、状态保存、通信

工程结构                                                                                       TabAFm到TabEFm都是Fragment,并且每个Fragment对应一个布局文件. TabAFm.java                                                                             package com.yydcdut.tabho

Android ——TabHost使用

在Android中,通常可以使用切换卡(选项卡)实现切换显示不同页面内容的功能.这一功能可以通过TabHost控件来实现. 下面我们就通过一个简单的实例演示如何使用TabHost控件完成切换卡功能,完成后的运行效果如图1所示. 图1 主页显示效果 可以看出,在该实例中,总共设置了四个TabHost标签,分别为主页.时间.联系人和搜索.在点击这些标签时,便可以完成相应页面内容的显示. 1.界面布局 TabHost是整个Tab的容器,是由TabWidget和FrameLayout 两部分组成的.其中

【原创】android——Tabhost 自定义tab+底部实现+intent切换内容

1,实现tabhost自定义格式,再此仅仅显示背景和文字,效果图预览:(底边栏所示) (图片变形) 2,xml配置 activity_user的XML配置  1 <TabHost xmlns:android="http://schemas.android.com/apk/res/android" 2 xmlns:tools="http://schemas.android.com/tools" 3 android:id="@+id/tabhost&qu

Android TabHost(简易用法)

前言 欢迎大家我分享和推荐好用的代码段~~ 声明          欢迎转载,但请保留文章原始出处: CSDN:http://www.csdn.net 雨季o莫忧离:http://blog.csdn.net/luckkof 正文 Tab应用的结构 TabHost的Activity的结构如下: <?xml version="1.0" encoding="utf-8"?> <!-- 定义TabHost组件 --> <LinearLayout

Android tabhost下的activity怎样获取传来的值

android tabhost下的activity怎样获取传来的值,具体解决方案如下: 解决方案: 其他activity设置intent:Intent intent=new Intent(); intent.putExtra("键",值);//intent键值对传的值 intent.setClass(FromActivity.this,TabHostActivity.class); FromActivity.this.startActivity(intent);tabhostactic

Android TabHost 的美化与设计

用到的布局xml文件内容如下: <?xml version="1.0" encoding="utf-8"?> <TabHost xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/tabhost" android:layout_width="fill_parent" andro

修炼-------------Android TabHost,TabWidget选项卡总结

修炼-------------Android TabHost,TabWidget选项卡总结 Android之TabHost TabHost,个人理解为选项卡的容器,是一种特殊的FrameLayout布局(帧布局) 根据SDK文档, Container for a tabbed window view. This object holds two children: a set of tab labels that the user clicks to select a specific tab,

Android tabhost 切换activity时数据不刷新

解决方案 在android中,使用tabHost的时候,如果tab被点击,该tab所对应的activity被加载了,从别的tab切换回来的时候,activity不会再次被创建了(onCreate),所以要想每次点击tab都刷新activity,有如下方法: 方法1 把要刷新的对象添加到onresume 1 @Override 2 public void onResume() { 3 super.onResume(); 4 //代码 5 } 每次切换tab,该activity会调用次方法onres

Android TabHost 动态修改图标或者动态改变标题

那时客户需要实现在TabHost标题上动态显示从数据库获取的个数.起初这样思考的,从数据库 获取个数是非常简单,但是要把获取的个数显示在TabHost标题,思前想后,想用Handler来异步实现消息传递. 如果将图标或者标题的变量设置为全局变量,你们应该知道我的目的吧.也就是为了在这个类不断的进行赋值. 先来简单的认识下TabHost吧. xml的文件代码: <?xml version="1.0" encoding="utf-8"?> <TabHo