欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

Android TabWidget底部显示效果

程序员文章站 2023-12-13 17:36:16
tabhost控件默认使用linearlayout包裹tabwidget和framelayout,布局文件如下:

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下测试通过。

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

上一篇:

下一篇: