默认的tabhost中的tabwidget是放在顶部的,有时需要将TAB移到底部来,这时需要在XML中做些细微的变动,如下:
view plaincopy to clipboardprint?
01.<?xml version="1.0" encoding="utf-8"?>
02.<LinearLayout
03. xmlns:android="http://schemas.android.com/apk/res/android"
04. android:orientation="vertical"
05. android:layout_width="fill_parent"
06. android:layout_height="fill_parent">
07. <TabHost
08. android:id="@+id/tabhost"
09. 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>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabHost
android:id="@+id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingBottom="62px">
<AnalogClock
android:id="@+id/tab1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerHorizontal="true" />
<Button
android:id="@+id/tab2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="A semi-random button" />
</FrameLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabWidget
android:id="@android:id/tabs"
android:layout_alignParentBottom="true"
android:layout_width="fill_parent"
android:layout_height="60px" />
</RelativeLayout>
</TabHost>
</LinearLayout>
我们将tabWidget放到一个relativeLayout中,然后加上这句android:layout_alignParentBottom="true",代码实现如下
view plaincopy to clipboardprint?
01.public class TabTest2 extends Activity {
02. public void onCreate(Bundle icicle) {
03. super.onCreate(icicle);
04. setContentView(R.layout.tabtest2);
05. TabHost tabs=(TabHost)findViewById(R.id.tabhost);
06.
07. tabs.setup();
08.
09. 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.}
public class TabTest2 extends Activity {
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.tabtest2);
TabHost tabs=(TabHost)findViewById(R.id.tabhost);
tabs.setup();
TabHost.TabSpec spec=tabs.newTabSpec("tag1");
spec.setContent(R.id.tab1);
spec.setIndicator("Clock");
tabs.addTab(spec);
spec=tabs.newTabSpec("tag2");
spec.setContent(R.id.tab2);
spec.setIndicator("Button");
tabs.addTab(spec);
tabs.setCurrentTab(0);
}
}
这样就可以把tab置于页面底部了,其实跟上次讲的LinearLayout的buttonBar样式有点类似
转载地址:
http://blog.csdn.net/roadog2006/archive/2010/04/12/5475549.aspx
分享到:
相关推荐
博客地址 http://blog.csdn.net/sbsujjbcy/article/details/46808177
Android中底部tab,中间凸起按钮的效果
实现了Android的底部tab切换界面,并实现了不同tab有不同的标题显示样式。这在项目中很常用。
Android底部导航条、底部tab中间凸起效果,中间凸出按钮,可用于签到、发布等的凸出效果
高仿新浪微博的底部Tab布局,基于Activity实现
Android滑动切换tab(切换带动画)
所有页面都可保持底部Tab不变,(本人亲测)友友们我会更新更多的源码和大家分享,希望大家喜欢
Android 自定义底部TAB Android 自定义底部TAB Android 自定义底部TAB
类似微信底部tab切换效果类似微信底部tab切换效果类似微信底部tab切换效果类似微信底部tab切换效果类似微信底部tab切换效果类似微信底部tab切换效果类似微信底部tab切换效果类似微信底部tab切换效果类似微信底部tab...
android底部Tab并且带标题栏 Tab在底部实现并且实现标题栏
Android 顶部底部均有Tab标签 http://blog.csdn.net/geofferysun/article/details/41826451
本篇文章主要介绍了Android TabLayout 实现底部Tab的示例代码,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
android 自定义中间带圆形按钮的底部导航控件.rar,太多无法一一验证是否可用,程序如果跑不起来需要自调,部分代码功能进行参考学习。
自定义的一个卡劵效果View,代码为AS构建,实现分析请看博客http://blog.csdn.net/yissan/article/details/51429281
Android 采用TAB的方式实现微信底部菜单,并且配合单击操作实现主界面的文字滚动。 这里创建了ViewPager mViewPager用来放置界面切换,初始化View适配器后,新建ArrayList,用来存放微信底部菜单的4个Tab,四个Tab...
fleep滑动切换tab切换带动画.zip
Android 底部导航栏 (底部 Tab) 最佳实践
自定义Android中TabHost组件显示在屏幕底部,并实现滑动切换页面。在此基础上可以实现类似米聊等软件主界面的Tab效果。
android Tab底部切换,大家可以学习参考一下,点击下面的tab,就可以实现不同页面的切换