希望tabwigdet在屏幕的下方,类似iphone的效果,经过研究发现使用布局文件可以非常简陋的实现类似的效果,当然没有iphone的漂亮:
主的tabactivity布局文件如下所示:
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
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:layout_weight="10" />
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
</TabHost>
这里如果直接把tabwidget放在framelayout下面是不行的,因为framelayout的height属性是fill_parent,会把tabwidget的空间完全填满,导致看不到tabwidget。
故需要使用layout_weight属性,并且经过试验如果framelayout的weight属性值小于10的话,tab只能显示出图片,标签仍然显示不出来。
补充:如果设置tabweight的weight=0, framelayout的weight=1也可以完全显示,推荐使用这个组合。
至于weight的值应该如何设置还不是太清楚,目前只知道值越小显示的权重越大。