TabHost的后期通胀过程中出错

时间:2011-05-04 00:42:20

标签: java android eclipse android-tabhost android-framelayout

我在TabHost中有一个FrameLayout。我收到以下错误。如何让它在Eclipse中呈现?

Error during post inflation process:
The FrameLayout for the TabHost has no content. Rendering failed.

这是我的XML

<?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">

    <!-- 
    <RelativeLayout android:layout_height="wrap_content" android:layout_width="match_parent" android:id="@+id/actionbarRelativeLayout">
        <ImageButton android:layout_height="wrap_content" android:layout_width="wrap_content" android:src="@drawable/icon" android:id="@+id/stocktwitsImageButton"></ImageButton>
        <ImageButton android:layout_height="wrap_content" android:layout_width="wrap_content" android:src="@drawable/icon" android:id="@+id/composeImageButton" android:layout_alignParentRight="true"></ImageButton>
    </RelativeLayout>
-->

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:padding="5dp">
        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />
        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:padding="5dp" />
    </LinearLayout>
</TabHost>

1 个答案:

答案 0 :(得分:1)

这是从Android的源setupTabHost方法中提取的:

final int count = content.getChildCount();

if (count == 0) {
    throw new PostInflateException(
            "The FrameLayout for the TabHost has no content. Rendering failed.\n");
}

正如例外所说,你需要有内容。将XML重构为:

<FrameLayout android:id="@android:id/tabcontent"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="5dp"> 
    <LinearLayout android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:id="@+id/tab1"></LinearLayout>
</FrameLayout>