android 底部tab效果,Android TabWidget底部显示效果

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

android:id="@android:id/tabhost"

android:layout_width="match_parent"

android:layout_height="match_parent" >

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical" >

android:id="@android:id/tabs"

android:layout_width="match_parent"

android:layout_height="wrap_content" >

android:id="@android:id/tabcontent"

android:layout_width="match_parent"

android:layout_height="match_parent" >

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

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

android:id="@+id/tabhost"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:layout_alignParentLeft="true"

android:layout_alignParentTop="true" >

android:layout_width="match_parent"

android:layout_height="match_parent">

android:id="@android:id/tabs"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_alignParentBottom="true">

android:id="@android:id/tabcontent"

android:layout_width="match_parent"

android:layout_height="match_parent" >

方式二:

1、将LinearLayout中TabWidget和FrameLayout交换位置

2、设置FrameLayout的属性:android:layout_weight="1" android:layout_height="0dp"

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" >

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical" >

android:id="@android:id/tabcontent"

android:layout_width="match_parent"

android:layout_height="0dp"

android:layout_weight="1" >

android:id="@android:id/tabs"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_alignParentBottom="true">

方式三:

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

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

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

android:id="@+id/tabhost"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:layout_alignParentLeft="true"

android:layout_alignParentTop="true" >

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical" >

android:id="@android:id/tabcontent"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:layout_gravity="top" >

android:id="@android:id/tabs"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_gravity="bottom">

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

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程小技巧。

总结

如果觉得编程之家网站内容还不错,欢迎将编程之家网站推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。

小编个人微信号 jb51ccc

喜欢与人分享编程技术与工作经验,欢迎加入编程之家官方交流群!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值