android实现界面底部的tab

默认的tabhost中的tabwidget是放在顶部的,有时需要将TAB移到底部来,这时需要在XML中做些细微的变动,如下:

 

 

[xhtml] view plain copy
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout  
  3.     xmlns:android="http://schemas.android.com/apk/res/android"  
  4.     android:orientation="vertical"  
  5.     android:layout_width="fill_parent"  
  6.     android:layout_height="fill_parent">  
  7.     <TabHost  
  8.         android:id="@+id/tabhost"  
  9.         android:layout_width="fill_parent"  
  10.         android:layout_height="fill_parent">  
  11.         <FrameLayout  
  12.             android:id="@android:id/tabcontent"  
  13.             android:layout_width="fill_parent"  
  14.             android:layout_height="fill_parent"  
  15.             android:paddingBottom="62px">  
  16.             <AnalogClock  
  17.                 android:id="@+id/tab1"  
  18.                 android:layout_width="fill_parent"  
  19.                 android:layout_height="fill_parent"  
  20.                 android:layout_centerHorizontal="true" />  
  21.             <Button  
  22.                 android:id="@+id/tab2"  
  23.                 android:layout_width="fill_parent"  
  24.                 android:layout_height="fill_parent"  
  25.                 android:text="A semi-random button" />  
  26.         </FrameLayout>  
  27.         <RelativeLayout  
  28.             android:layout_width="fill_parent"  
  29.             android:layout_height="fill_parent">  
  30.             <TabWidget  
  31.                 android:id="@android:id/tabs"  
  32.                 android:layout_alignParentBottom="true"  
  33.                 android:layout_width="fill_parent"  
  34.                 android:layout_height="60px" />  
  35.         </RelativeLayout>  
  36.     </TabHost>  
  37. </LinearLayout>  
 

 

我们将tabWidget放到一个relativeLayout中,然后加上这句android:layout_alignParentBottom="true",代码实现如下

  1. public class TabTest2 extends Activity {  
  2.     public void onCreate(Bundle icicle) {  
  3.         super.onCreate(icicle);  
  4.         setContentView(R.layout.tabtest2);  
  5.         TabHost tabs=(TabHost)findViewById(R.id.tabhost);  
  6.           
  7.         tabs.setup();  
  8.           
  9.         TabHost.TabSpec spec=tabs.newTabSpec("tag1");  
  10.         spec.setContent(R.id.tab1);  
  11.         spec.setIndicator("Clock");  
  12.         tabs.addTab(spec);  
  13.           
  14.         spec=tabs.newTabSpec("tag2");  
  15.         spec.setContent(R.id.tab2);  
  16.         spec.setIndicator("Button");  
  17.         tabs.addTab(spec);  
  18.           
  19.         tabs.setCurrentTab(0);  
  20.     }  
  21. }  
 

 

这样就可以把tab置于页面底部了,其实跟上次讲的LinearLayout的buttonBar样式有点类似


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值