clcurie_11 2013-10-10 06:59 采纳率: 6.7%
浏览 1310

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>

请问如何修改呢?

  • 写回答

1条回答

  • ChatGPTᴼᴾᴱᴺᴬᴵ 2023-03-22 14:50
    关注

    该回答引用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>
    

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

    评论

报告相同问题?

悬赏问题

  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。