TabHost控件默认使用LinearLayout包裹TabWidget和FrameLayout,布局文件如下:

  1. <TabHost xmlns:android="http://schemas.android.com/apk/res/android"
  2. android:id="@android:id/tabhost"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent" >
  5. <LinearLayout
  6. android:layout_width="match_parent"
  7. android:layout_height="match_parent"
  8. android:orientation="vertical" >
  9. <TabWidget
  10. android:id="@android:id/tabs"
  11. android:layout_width="match_parent"
  12. android:layout_height="wrap_content" >
  13. </TabWidget>
  14. <FrameLayout
  15. android:id="@android:id/tabcontent"
  16. android:layout_width="match_parent"
  17. android:layout_height="match_parent" >
  18. </FrameLayout>
  19. </LinearLayout>
  20. </TabHost>

这样TabWidget显示在顶部,如果想把TabWidget放到底部有三种方式。

方式一:将TabHost中默认的LinearLayout换成RelativeLayout,并给TabWidget添加Android:layout_alignParentBottom="true"

  1. <TabHost xmlns:android="http://schemas.android.com/apk/res/android"
  2. android:id="@+id/tabhost"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent"
  5. android:layout_alignParentLeft="true"
  6. android:layout_alignParentTop="true" >
  7. <RelativeLayout
  8. android:layout_width="match_parent"
  9. android:layout_height="match_parent">
  10. <TabWidget
  11. android:id="@android:id/tabs"
  12. android:layout_width="match_parent"
  13. android:layout_height="wrap_content"
  14. android:layout_alignParentBottom="true">
  15. </TabWidget>
  16. <FrameLayout
  17. android:id="@android:id/tabcontent"
  18. android:layout_width="match_parent"
  19. android:layout_height="match_parent" >
  20. </FrameLayout>
  21. </RelativeLayout>
  22. </TabHost>

方式二:1、将LinearLayout中TabWidget和FrameLayout交换位置
              2、设置FrameLayout的属性:android:layout_weight="1" android:layout_height="0dp"

  1. <p><TabHost xmlns:android="<a target=_blank href="http://schemas.android.com/apk/res/android">http://schemas.android.com/apk/res/android</a>"
  2. android:id="@+id/tabhost"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent"
  5. android:layout_alignParentLeft="true"
  6. android:layout_alignParentTop="true" ></p><p>   <LinearLayout
  7. android:layout_width="match_parent"
  8. android:layout_height="match_parent"
  9. android:orientation="vertical" >
  10. <FrameLayout
  11. android:id="@android:id/tabcontent"
  12. android:layout_width="match_parent"
  13. android:layout_height="0dp"
  14. android:layout_weight="1" >
  15. </FrameLayout>
  16. <TabWidget
  17. android:id="@android:id/tabs"
  18. android:layout_width="match_parent"
  19. android:layout_height="wrap_content"
  20. android:layout_alignParentBottom="true">
  21. </TabWidget>
  22. </LinearLayout>
  23. </TabHost></p>

方式三:1、将TabWidget移动到LinearLayout标签以下
              2、在FrameLayout中加入属性:android:layout_gravity="top"
              3、在TabWidget中加入属性:android:layout_gravity="bottom"

  1. <TabHost xmlns:android="http://schemas.android.com/apk/res/android"
  2. android:id="@+id/tabhost"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent"
  5. android:layout_alignParentLeft="true"
  6. android:layout_alignParentTop="true" >
  7. <LinearLayout
  8. android:layout_width="match_parent"
  9. android:layout_height="match_parent"
  10. android:orientation="vertical" >
  11. <FrameLayout
  12. android:id="@android:id/tabcontent"
  13. android:layout_width="match_parent"
  14. android:layout_height="match_parent"
  15. android:layout_gravity="top" >
  16. </FrameLayout>
  17. </LinearLayout>
  18. <TabWidget
  19. android:id="@android:id/tabs"
  20. android:layout_width="match_parent"
  21. android:layout_height="wrap_content"
  22. android:layout_gravity="bottom">
  23. </TabWidget>
  24. </TabHost>

以上三种方式在Android4.2下测试通过。

Android TabWidget底部显示的更多相关文章

  1. android BottomNavigationView 底部显示3个以上的item

    你现在可以用app:labelVisibilityMode="[labeled, unlabeled, selected, auto] labeled 所有的标签都是可见的. unlabel ...

  2. Android应用底部导航栏(选项卡)实例

    现在很多android的应用都采用底部导航栏的功能,这样可以使得用户在使用过程中随意切换不同的页面,现在我采用TabHost组件来自定义一个底部的导航栏的功能. 我们先看下该demo实例的框架图: 其 ...

  3. Android自定义底部带有动画的Dialog

    Android自定义底部带有动画的Dialog 效果图 先看效果图,是不是你想要的呢 自定义Dialog package --.view; import android.app.Dialog; imp ...

  4. dialog自适应大小、固定大小、底部显示

    创建一个从底部显示的对话框 if (dialog == null) { dialog = new Dialog(context, R.style.theme_from_bottom); View vi ...

  5. Android动态控制状态栏显示和隐藏

    记得之前有朋友在留言里让我写一篇关于沉浸式状态栏的文章,正巧我确实有这个打算,那么本篇就给大家带来一次沉浸式状态栏的微技巧讲解. 其实说到沉浸式状态栏这个名字我也是感到很无奈,真不知道这种叫法是谁先发 ...

  6. Android 全屏显示

    Android全屏显示: @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInst ...

  7. Android之垂直显示TextView

    Android之垂直显示TextView 1因为界面需求原因,需要TextView垂直显示,话不多说,看代码,我也是搜的例子,在此感谢写这个例子的大神,在此做个笔记和分享给大家 2.用到了自定义控件的 ...

  8. Android 修改底部导航栏navigationbar的颜色

    Android 修改底部导航栏navigationbar的颜色 getWindow().setNavigationBarColor(Color.BLUE); //写法一 getWindow().set ...

  9. Android在ListView显示图片(重复混乱闪烁问题)

    Android在ListView显示图片(重复混乱闪烁问题) 1.原因分析 ListView item缓存机制: 为了使得性能更优,ListView会缓存行item(某行相应的View). ListV ...

随机推荐

  1. Spring透过ApplicationListener来触发contextrefreshedevent事件

    Spring通过ApplicationListener接口来触发contextrefreshedevent事件在开发时有时候需要在整个应用开始运行时执行一些特定代码,比如初始化环境,准备测试数据.加载 ...

  2. LINUX+Vmware+SVN的配置和安装

    LINUX+Vmware+SVN的配置和安装 验证SVN安装了没有 svnserve --version 查看CentOS自带JDK是否已安装. ◆输入:yum list installed |gre ...

  3. Git/GitHub 初用体验与总结

    Git,一个神奇而又陌生的东西,居然到现在才去了解它,就像有一位仁兄说的,现在不会用Git真的都不好意思说自己搞IT的. 简单的讲,这Git是目前最先进的分布式版本控制系统,和他相对应的就是众所周知的 ...

  4. 【译】Import Changes from Direct3D 11 to Direct3D 12

    译者:林公子 出处:木木的二进制人生 转载请注明作者和出处,谢谢! 这是微软公布的Direct3D 12文档的其中一篇,此翻译留作学习记录备忘,水平有限,错漏难免,还望海涵. 原文链接是https:/ ...

  5. Qt qml 模拟iphone slide to unlock 的聚光动画文字效果

    模拟iphone slide to unlock 的聚光动画文字效果    /底层放淡文字    /前景放高亮文字+半透明遮罩    /动画移动遮罩 Author: surfsky.cnblogs.c ...

  6. 基于Session的国际化实现

    如何将我们网站的其它内容(如菜单.标题等)做国际化处理呢?这就是本篇要将的内容—>国际化. 在项目的spring.xml文件添加的内容如下 <mvc:interceptors> &l ...

  7. bzoj3223 文艺平衡树

    传送门 :http://www.lydsy.com/JudgeOnline/problem.php?id=3223 splay区间翻转的基础题,然而我还是调了一晚上(蒟蒻的悲哀) #include & ...

  8. 位图切割器&位图裁剪器

    位图切割器: 虽然网上有类似的工具,PhotoShop 也有类似功能,但前者似乎不支持超大位图切割(以 G 计大小),而后者的切割块数量好像有比较小的限定范围,于是自己动手写了这个工具. 至于为什么是 ...

  9. 看守所、戒毒所3D指纹门禁系统解决方案

    为响应"科技强警"的战略方针,华本构建了一个完整的.集成的.可靠的.易操作的高安全性门禁系统,应用于看守所.戒毒所.公安局和部队等单位,使管理更现代化.规范化,有效地预防和制止越狱 ...

  10. Openstack+Kubernetes+Docker微服务实践之路--Kubernetes

    经过几番折腾终于搞定Kubernetes了,我们要在Openstack上部署Kubernetes集群,使用最新工具Kubeadm来安装,由于不能直接访问Kubernetes的源,我们需要一台可以穿墙的 ...