tabhost 中的横向 scrollview 不能运行或者内容消失

main.xml 包含 tabhost。
现在的问题是横向的 scrollview 不能运行,如果我改变 relative layout 到 linearlayout 标签是可以滚动的,但是却不能在 activity 上看见主要内容,只能看见 tabs。

我也想完全删除 linear layout,包含 tabwidget,但是什么也没有改变。
代码如下:

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@android:id/tabhost" 
    android:paddingTop="@dimen/tab_space_top"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >
    <RelativeLayout android:id="@+id/tab_relative_layout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        >
        <HorizontalScrollView android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:fillViewport="true"
                android:scrollbars="none">
                <LinearLayout android:id="@+id/tab_linear_layout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
        <TabWidget android:id="@android:id/tabs"
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content">
            </TabWidget>
            </LinearLayout>
            </HorizontalScrollView>
        <FrameLayout android:id="@android:id/tabcontent"
            android:layout_width="fill_parent" 
            android:layout_height="fill_parent"
            android:layout_below="@android:id/tabs">

        </FrameLayout>

    </RelativeLayout>
</TabHost>

请问如何修改呢?

该回答引用ChatGPT-3.5

您可以尝试以下步骤来解决您的问题:

  • 将 TabHost 中的 RelativeLayout 更改为 LinearLayout。
  • 在 LinearLayout 中嵌套一个 HorizontalScrollView,并将它的 android:layout_width 设置为 wrap_content,android:layout_height 设置为 fill_parent。
  • 在 HorizontalScrollView 中嵌套一个 LinearLayout,并将它的 android:layout_width 设置为 wrap_content,android:layout_height 设置为 fill_parent。
  • 将 TabWidget 添加到内部的 LinearLayout 中,并将它的 android:layout_width 设置为 wrap_content,android:layout_height 设置为 fill_parent。
  • 在 LinearLayout 下方添加您的主要内容。

以下是修改后的代码示例:

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:paddingTop="@dimen/tab_space_top"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <HorizontalScrollView
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:fillViewport="true"
            android:scrollbars="none">

            <LinearLayout
                android:id="@+id/tab_linear_layout"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent">

                <TabWidget
                    android:id="@android:id/tabs"
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent" />
            </LinearLayout>
        </HorizontalScrollView>

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1" />

        <!-- 主要内容在这里添加 -->

    </LinearLayout>
</TabHost>

希望这可以解决您的问题。