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

<?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",代码实现如下

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样式有点类似

更多相关文章

  1. Android Layout 布局 && Android自带样式(theme)&& CheckBox样例 &
  2. Android开发 - 设置EditText的样式
  3. Android 中DatePicker和TimePicker 修改不同样式
  4. android actionbar 自定义样式
  5. 2010-03-06 传智播客—Android(六)通知、样式、主题、HTML
  6. Android中的样式和主题(style & theme)

随机推荐

  1. Flutter(环境搭建-Android视角)
  2. android硬编码h264-MediaCodec
  3. 1. 2 Textview 及其子类
  4. Android 多媒体应用——MediaPlayer音频
  5. Android Intent实现页面跳转的方法示例
  6. Android(安卓)组件系列之Activity的传值
  7. android之逐帧动画
  8. Android(安卓)Shape控件美化实现代码
  9. android ListView Item和CheckBox、Butto
  10. Android评分控件RatingBar使用实例解析