[douban] 02_豆瓣主界面-TabHost

Android 4.0

豆瓣主界面-TabHost
TabHost

默认的TabHost布局三个问题
1、TabWidget移到界面底部,默认在顶部
解决:
①在TabHost外包裹RelativeLayout
TabWidget增加属性android:layout_gravity="bottom",使其底层对齐

2、自定义TabWidget-默认的图片和文字重叠了,很丑,且有一条横线
TabSpec.setIndicator(view);

3、FrameLayout和TabWidget内容重复了,也就是FrameLayout覆盖了TabWidget的内容
解决1:如果TabWidget要在底部,那么在FrameLayout中采用layout_marginBottom属性,使其刚好留出来TabWidget的高度
解决2:如果TabWidget在顶部,那么直接使用LinearLayout,在FrameLayout使用layout_weight = 1 , layout_weight  = 0dp
TabWidget在下面,FrameLayout和TabWidget内容不重复解决方案:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <TabHost
        android:id="@android:id/tabhost"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <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"
                android:layout_above="@android:id/tabs" >
            </FrameLayout>
        </RelativeLayout>

    </TabHost>
</RelativeLayout>
效果: