设置tabhost位于底部的三种方法

对于Android自带的tabhost组件,是位于页面顶端的,若想让其位于页面底端,在这里提供两种方法。
 
方法一
1、tabcontent和tabs交换位置
 
2、设置tabcontent的属性:android:layout_weight="1"
 
范例
[ html]  
<?xml version="1.0" encoding="utf-8"?>  
<RelativeLayout xmlns:android=" http://schemas.android.com/apk/res/android"  
    android:layout_width="match_parent"  
    android:layout_height="match_parent" >  
  
    <TabHost  
        android:id="@android:id/tabhost"  
        android:layout_width="match_parent"  
        android:layout_height="match_parent"  
        android:layout_alignParentLeft="true"  
        android:layout_alignParentBottom="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_weight="1" >  
  
                中间部分省略  
                  
            </FrameLayout>  
  
            <TabWidget  
                android:id="@android:id/tabs"  
                android:layout_width="match_parent"  
                android:layout_height="wrap_content" >  
            </TabWidget>  
        </LinearLayout>  
    </TabHost>  
  
</RelativeLayout>  
 
 
方法二
1、tabcontent和tabs交换位置
 
2、将tabs放到一个relativeLayout中,然后加上如下属性:android:layout_alignParentBottom="true"
范例
[html] 
<?xml version="1.0" encoding="utf-8"?>  
<RelativeLayout xmlns:android=" http://schemas.android.com/apk/res/android"  
    android:layout_width="match_parent"  
    android:layout_height="match_parent" >  
  
    <TabHost  
        android:id="@android:id/tabhost"  
        android:layout_width="match_parent"  
        android:layout_height="match_parent"  
        android:layout_alignParentLeft="true"  
        android:layout_alignParentBottom="true"  >  
  
        <FrameLayout  
            android:id="@android:id/tabcontent"  
            android:layout_width="match_parent"  
            android:layout_height="match_parent" >  
  
                中间部分省略  
                  
        </FrameLayout>  
  
        <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>  
        </RelativeLayout>  
    </TabHost>  
  
</RelativeLayout>  
 
方法三
1、将tabcontent和tabs交换位置(tabs移动到LinearLayout标签以下)
2、在tabcontent中加入属性:android:layout_gravity="top"
3、在tabs中加入属性:android:layout_gravity="bottom" 
范例
[html]  <?xml version="1.0" encoding="UTF-8"?>  
<RelativeLayout xmlns:android=" http://schemas.android.com/apk/res/android"  
    android:layout_width="fill_parent"  
    android:layout_height="fill_parent" >  
  
    <TabHost  
        android:id="@android:id/tabhost"  
        android:layout_width="match_parent"  
        android:layout_height="match_parent"  
        android:layout_alignParentBottom="true"  
        android:layout_alignParentLeft="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>  
  
</RelativeLayout>  

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值