广告
返回顶部
首页 > 资讯 > 移动开发 >Android TabWidget底部显示效果
  • 868
分享到

Android TabWidget底部显示效果

Android 2022-06-06 11:06:39 868人浏览 泡泡鱼
摘要

TabHost控件默认使用LinearLayout包裹TabWidget和FrameLayout,布局文件如下: <TabHost xmlns:Android="Htt

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


<TabHost xmlns:Android="Http://schemas.android.com/apk/res/android" 
 android:id="@android:id/tabhost" 
 android:layout_width="match_parent" 
 android:layout_height="match_parent" > 
 <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" > 
  </TabWidget> 
  <FrameLayout 
   android:id="@android:id/tabcontent" 
   android:layout_width="match_parent" 
   android:layout_height="match_parent" > 
  </FrameLayout> 
 </LinearLayout> 
</TabHost> 

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

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


<TabHost xmlns:android="http://schemas.android.com/apk/res/android" 
 android:id="@+id/tabhost" 
 android:layout_width="match_parent" 
 android:layout_height="match_parent" 
 android:layout_alignParentLeft="true" 
 android:layout_alignParentTop="true" > 
 <RelativeLayout 
  android:layout_width="match_parent" 
  android:layout_height="match_parent"> 
  <TabWidget 
   android:id="@android:id/tabs" 
   android:layout_width="match_parent" 
   android:layout_height="wrap_content" 
   android:layout_alignParentBottom="true"> 
  </TabWidget> 
  <FrameLayout 
   android:id="@android:id/tabcontent" 
   android:layout_width="match_parent" 
   android:layout_height="match_parent" > 
  </FrameLayout> 
 </RelativeLayout> 
</TabHost> 

方式二:

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


<TabHost xmlns:android="<a target=_blank href="http://schemas.android.com/apk/res/android" rel="external nofollow" >http://schemas.android.com/apk/res/android</a>" 
 android:id="@+id/tabhost" 
 android:layout_width="match_parent" 
 android:layout_height="match_parent" 
 android:layout_alignParentLeft="true" 
 android:layout_alignParentTop="true" ></p><p> <LinearLayout 
  android:layout_width="match_parent" 
  android:layout_height="match_parent" 
  android:orientation="vertical" > 
  <FrameLayout 
   android:id="@android:id/tabcontent" 
   android:layout_width="match_parent" 
   android:layout_height="0dp" 
   android:layout_weight="1" > 
  </FrameLayout> 
  <TabWidget 
   android:id="@android:id/tabs" 
   android:layout_width="match_parent" 
   android:layout_height="wrap_content" 
   android:layout_alignParentBottom="true"> 
  </TabWidget> 
 </LinearLayout> 
</TabHost>

方式三:

1、将TabWidget移动到LinearLayout标签以下             

2、在FrameLayout中加入属性:android:layout_gravity="top"             

3、在TabWidget中加入属性:android:layout_gravity="bottom"


<TabHost xmlns:android="http://schemas.android.com/apk/res/android" 
 android:id="@+id/tabhost" 
 android:layout_width="match_parent" 
 android:layout_height="match_parent" 
 android:layout_alignParentLeft="true" 
 android:layout_alignParentTop="true" > 
 <LinearLayout 
  android:layout_width="match_parent" 
  android:layout_height="match_parent" 
  android:orientation="vertical" > 
  <FrameLayout 
   android:id="@android:id/tabcontent" 
   android:layout_width="match_parent" 
   android:layout_height="match_parent" 
   android:layout_gravity="top" > 
  </FrameLayout> 
 </LinearLayout> 
 <TabWidget 
  android:id="@android:id/tabs" 
  android:layout_width="match_parent" 
  android:layout_height="wrap_content" 
  android:layout_gravity="bottom"> 
 </TabWidget> 
</TabHost> 

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

您可能感兴趣的文章:Android 仿微信底部渐变Tab效果Android 使用FragmentTabHost实现底部菜单功能Android中修改TabLayout底部导航条Indicator长短的方法Android编程实现将tab选项卡放在屏幕底部的方法Android中TabLayout+ViewPager 简单实现app底部Tab导航栏Android design包自定义tablayout的底部导航栏的实现方法关注Ionic底部导航按钮tabs在android情况下浮在上面的处理Android仿微信底部实现Tab选项卡切换效果android 选项卡(TabHost)如何放置在屏幕的底部Android TabLayout 实现底部Tab的示例代码


--结束END--

本文标题: Android TabWidget底部显示效果

本文链接: https://www.lsjlt.com/news/28245.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作