java - TabHost 的后期膨胀过程中出错

标签 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>

最佳答案

这是从 Android 的源代码 setupTabHost 方法中摘录的:

final int count = content.getChildCount();

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

正如异常(exception)所说,您需要有内容。将 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>

关于java - TabHost 的后期膨胀过程中出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5877305/

相关文章:

java - Spring Web MVC : How to use a ResponseEntity in the view class, 不是 Controller ?

Android:在TextView中静态下划线动态文本

Android 设备选择器 - 设备未显示

python - 清除 Python [Eclipse] 的命令行输出

java - 如何将 jssc.jar 添加到 Java 项目

java - 如何处理网络中断和连接池

java - 为什么运行示例 flink 应用程序会抛出此错误?

Java-如何交换2个数组元素并使用toString输出shell排序的每个交换?

android - 水平居中一组 View

java - 形状不显示