Android TabWidget底部显示

简介: TabHost控件默认使用LinearLayout包裹TabWidget和FrameLayout,布局文件如下: [html] view plain copy                                                                              这样TabWidget显示在顶部,如果想把TabWidget放到底部有三种方式。

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

[html]  view plain  copy
 
 在CODE上查看代码片派生到我的代码片
  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.   
  6.     <LinearLayout  
  7.         android:layout_width="match_parent"  
  8.         android:layout_height="match_parent"  
  9.         android:orientation="vertical" >  
  10.   
  11.         <TabWidget  
  12.             android:id="@android:id/tabs"  
  13.             android:layout_width="match_parent"  
  14.             android:layout_height="wrap_content" >  
  15.         </TabWidget>  
  16.   
  17.         <FrameLayout  
  18.             android:id="@android:id/tabcontent"  
  19.             android:layout_width="match_parent"  
  20.             android:layout_height="match_parent" >  
  21.         </FrameLayout>  
  22.     </LinearLayout>  
  23. </TabHost>  

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

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

[html]  view plain  copy
 
 在CODE上查看代码片派生到我的代码片
  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.   
  11.         <TabWidget  
  12.             android:id="@android:id/tabs"  
  13.             android:layout_width="match_parent"  
  14.             android:layout_height="wrap_content"   
  15.             android:layout_alignParentBottom="true">  
  16.         </TabWidget>  
  17.           
  18.         <FrameLayout  
  19.             android:id="@android:id/tabcontent"  
  20.             android:layout_width="match_parent"  
  21.             android:layout_height="match_parent" >  
  22.         </FrameLayout>  
  23.     </RelativeLayout>  
  24. </TabHost>  

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

[html]  view plain  copy
 
 在CODE上查看代码片派生到我的代码片
  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.    
  11.         <FrameLayout  
  12.             android:id="@android:id/tabcontent"  
  13.             android:layout_width="match_parent"  
  14.             android:layout_height="0dp"  
  15.             android:layout_weight="1" >  
  16.         </FrameLayout>  
  17.           
  18.         <TabWidget  
  19.             android:id="@android:id/tabs"  
  20.             android:layout_width="match_parent"  
  21.             android:layout_height="wrap_content"   
  22.             android:layout_alignParentBottom="true">  
  23.         </TabWidget>  
  24.     </LinearLayout>  
  25. </TabHost></p>  

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

[html]  view plain  copy
 
 在CODE上查看代码片派生到我的代码片
  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.   
  8.    <LinearLayout  
  9.         android:layout_width="match_parent"  
  10.         android:layout_height="match_parent"  
  11.         android:orientation="vertical" >  
  12.    
  13.         <FrameLayout  
  14.             android:id="@android:id/tabcontent"  
  15.             android:layout_width="match_parent"  
  16.             android:layout_height="match_parent"  
  17.             android:layout_gravity="top" >  
  18.         </FrameLayout>  
  19.     </LinearLayout>  
  20.     <TabWidget  
  21.         android:id="@android:id/tabs"  
  22.         android:layout_width="match_parent"  
  23.         android:layout_height="wrap_content"   
  24.         android:layout_gravity="bottom">  
  25.     </TabWidget>  
  26. </TabHost>  

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

相关文章
|
Android开发
Android 使用ViewPager实现手动左右切换页面和底部点点跟随切换效果
Android 使用ViewPager实现手动左右切换页面和底部点点跟随切换效果
234 0
|
数据处理 Android开发
关于安卓glide加载显示进度
安卓glide加载显示进度
451 0
|
7月前
|
XML Android开发 数据格式
Android 中如何设置activity的启动动画,让它像dialog一样从底部往上出来
在 Android 中实现 Activity 的对话框式过渡动画:从底部滑入与从顶部滑出。需定义两个 XML 动画文件 `activity_slide_in.xml` 和 `activity_slide_out.xml`,分别控制 Activity 的进入与退出动画。使用 `overridePendingTransition` 方法在启动 (`startActivity`) 或结束 (`finish`) Activity 时应用这些动画。为了使前 Activity 保持静止,可定义 `no_animation.xml` 并在启动新 Activity 时仅设置新 Activity 的进入动画。
230 12
|
7月前
|
Android开发 UED
Android采用Scroller实现底部二楼效果
Android采用Scroller实现底部二楼效果
66 0
Android采用Scroller实现底部二楼效果
|
8月前
|
Android开发 UED
|
9月前
|
XML Java Android开发
Android Studio App开发之实现底部标签栏BottomNavigationView和自定义标签按钮实战(附源码 超详细必看)
Android Studio App开发之实现底部标签栏BottomNavigationView和自定义标签按钮实战(附源码 超详细必看)
827 0
|
Android开发
Android底部弹窗的正确打开方式2
Android底部弹窗的正确打开方式
|
XML Android开发 数据格式
Android底部弹窗的正确打开方式1
Android底部弹窗的正确打开方式
|
Android开发 C++
Android OpenGL显示任意3D模型文件
Android OpenGL显示任意3D模型文件
Android OpenGL显示任意3D模型文件
|
存储 缓存 Java
Android OpenGL 显示基本图形及相关概念解读
Android OpenGL 显示基本图形及相关概念解读
Android OpenGL 显示基本图形及相关概念解读

热门文章

最新文章

  • 1
    【08】flutter完成屏幕适配-重建Android,增加GetX路由,屏幕适配,基础导航栏-多版本SDK以及gradle造成的关于fvm的使用(flutter version manage)-卓伊凡换人优雅草Alex-开发完整的社交APP-前端客户端开发+数据联调|以优雅草商业项目为例做开发-flutter开发-全流程-商业应用级实战开发-优雅草Alex
  • 2
    Android历史版本与APK文件结构
  • 3
    【01】噩梦终结flutter配安卓android鸿蒙harmonyOS 以及next调试环境配鸿蒙和ios真机调试环境-flutter项目安卓环境配置-gradle-agp-ndkVersion模拟器运行真机测试环境-本地环境搭建-如何快速搭建android本地运行环境-优雅草卓伊凡-很多人在这步就被难倒了
  • 4
    当flutter react native 等混开框架-并且用vscode-idea等编译器无法打包apk,打包安卓不成功怎么办-直接用android studio如何打包安卓apk -重要-优雅草卓伊凡
  • 5
    APP-国内主流安卓商店-应用市场-鸿蒙商店上架之必备前提·全国公安安全信息评估报告如何申请-需要安全评估报告的资料是哪些-优雅草卓伊凡全程操作
  • 6
    【03】仿站技术之python技术,看完学会再也不用去购买收费工具了-修改整体页面做好安卓下载发给客户-并且开始提交网站公安备案-作为APP下载落地页文娱产品一定要备案-包括安卓android下载(简单)-ios苹果plist下载(稍微麻烦一丢丢)-优雅草卓伊凡
  • 7
    【09】flutter首页进行了完善-采用android studio 进行真机调试开发-增加了直播间列表和短视频人物列表-增加了用户中心-卓伊凡换人优雅草Alex-开发完整的社交APP-前端客户端开发+数据联调|以优雅草商业项目为例做开发-flutter开发-全流程-商业应用级实战开发-优雅草Alex
  • 8
    【02】仿站技术之python技术,看完学会再也不用去购买收费工具了-本次找了小影-感觉页面很好看-本次是爬取vue需要用到Puppeteer库用node.js扒一个app下载落地页-包括安卓android下载(简单)-ios苹果plist下载(稍微麻烦一丢丢)-优雅草卓伊凡
  • 9
    Cellebrite UFED 4PC 7.71 (Windows) - Android 和 iOS 移动设备取证软件
  • 10
    escrcpy:【技术党必看】Android开发,Escrcpy 让你无线投屏新体验!图形界面掌控 Android,30-120fps 超流畅!🔥
  • 1
    android FragmentManager 删除所有Fragment 重建
    15
  • 2
    Android实战经验之Kotlin中快速实现MVI架构
    21
  • 3
    即时通讯安全篇(一):正确地理解和使用Android端加密算法
    24
  • 4
    escrcpy:【技术党必看】Android开发,Escrcpy 让你无线投屏新体验!图形界面掌控 Android,30-120fps 超流畅!🔥
    39
  • 5
    【01】噩梦终结flutter配安卓android鸿蒙harmonyOS 以及next调试环境配鸿蒙和ios真机调试环境-flutter项目安卓环境配置-gradle-agp-ndkVersion模拟器运行真机测试环境-本地环境搭建-如何快速搭建android本地运行环境-优雅草卓伊凡-很多人在这步就被难倒了
    122
  • 6
    Cellebrite UFED 4PC 7.71 (Windows) - Android 和 iOS 移动设备取证软件
    40
  • 7
    【03】仿站技术之python技术,看完学会再也不用去购买收费工具了-修改整体页面做好安卓下载发给客户-并且开始提交网站公安备案-作为APP下载落地页文娱产品一定要备案-包括安卓android下载(简单)-ios苹果plist下载(稍微麻烦一丢丢)-优雅草卓伊凡
    55
  • 8
    Android历史版本与APK文件结构
    149
  • 9
    【02】仿站技术之python技术,看完学会再也不用去购买收费工具了-本次找了小影-感觉页面很好看-本次是爬取vue需要用到Puppeteer库用node.js扒一个app下载落地页-包括安卓android下载(简单)-ios苹果plist下载(稍微麻烦一丢丢)-优雅草卓伊凡
    46
  • 10
    【01】仿站技术之python技术,看完学会再也不用去购买收费工具了-用python扒一个app下载落地页-包括安卓android下载(简单)-ios苹果plist下载(稍微麻烦一丢丢)-客户的麻将软件需要下载落地页并且要做搜索引擎推广-本文用python语言快速开发爬取落地页下载-优雅草卓伊凡
    40