TabWidget在Android 2.1设备中看起来不正确

时间:2012-10-31 11:51:03

标签: android android-layout

我的应用已将android:targetSdkVersion设置为11.它使用TabHostTabWidget两个标签。但是,android:minSdkVersion设置为7(Android 2.1)。

我使用Android支持库(android-support-v13.jar)。我的选项卡在我能够测试的任何地方看起来都很好,除了在2.1中它们看起来是剪切构成选项卡内容的视图部分。这个问题在模拟器中也是可重现的。

这是布局文件的相关部分:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/repeat_layout"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

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

        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android: />

        <FrameLayout>
        ...
        </FrameLayout>
    </TabHost>
</LinearLayout>

以下是我希望标签看起来的方式:

Expected

以下是我在2.3设备中获得的内容:

Unexpected

基本上,Tabs似乎比他们需要的高,并且与下面FrameLayout的内容不必要地重叠。

解: 主要面向未来的访问者,如果您希望所有平台上的标签在低至2.1时保持一致,唯一的解决方案是使用自定义标签视图。你会在这里找到一个很棒的tutorial

1 个答案:

答案 0 :(得分:1)

试试这个

<?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:layout_width="fill_parent" android:layout_height="fill_parent"
        android:orientation="vertical" >

        <TabWidget android:layout_width="fill_parent" android:layout_height="wrap_content"
            android:layout_weight="0" android:id="@android:id/tabs"
            android:orientation="horizontal" />

        <FrameLayout android:layout_width="fill_parent" android:layout_height="0dp"
            android:layout_weight="1" android:id="@+android:id/realtabcontent" />

    </LinearLayout>
</TabHost>

希望它有所帮助...... !!干杯...