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>
    

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

    评论

报告相同问题?

悬赏问题

  • ¥35 平滑拟合曲线该如何生成
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站