温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

TabHost 置于底部 顶部的方法

发布时间:2020-07-08 18:19:09 来源:网络 阅读:1794 作者:uncom2005 栏目:移动开发
对于Android自带的tabhost组件,是位于页面顶端的,若想让其位于页面底端,在这里提供两种方法。
 
方法一
1、tabcontent和tabs交换位置
 
2、设置tabcontent的属性:android:layout_weight="1"
 
 
<?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"

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

Android 实战教程类FaceBook,欢迎学习交流!!!!

http://edu.51cto.com/course/course_id-3153.html

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI