【问题标题】:Android - TabHost inside ScrollViewAndroid - ScrollView 内的 TabHost
【发布时间】:2011-01-27 17:28:22
【问题描述】:

我正在编写一个实现嵌套选项卡的应用程序。因为两组选项卡占用了相当多的空间,而且一般因为内容的性质,我想将整个内部的 TabHost 放入一个可滚动的结构中。我可以制作外部活动FrameLayout、LinearLayout、甚至ViewFlipper的tabcontent;当我尝试使其成为 ScrollView 时,程序崩溃。

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

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />
        <ScrollView
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"/>
    </LinearLayout>

</TabHost>

显然 TabHost 喜欢住在不可滚动的框架内。有什么办法可以解决这个问题而不会造成很多混乱?

【问题讨论】:

    标签: android scrollview android-tabhost tabwidget android-xml


    【解决方案1】:

    对不起,我自己想出来的。解决方案是将第二个 TabHost 包装在其自己的 XML 文件中的 ScrollView 中。效果很好。

    外层:

    <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">
    
        <LinearLayout
            android:orientation="vertical"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">
            <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"/>
        </LinearLayout>
    
    </TabHost>
    

    内部:

    <ScrollView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
    
        <TabHost 
            android:id="@android:id/tabhost"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">
    
            <LinearLayout
                android:orientation="vertical"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent">
                <TabWidget
                    android:id="@android:id/tabs"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content" />
                <ViewFlipper
                    android:id="@android:id/tabcontent"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"/>
            </LinearLayout>
    
        </TabHost>
    
    </ScrollView>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-01-31
      • 1970-01-01
      • 1970-01-01
      • 2014-10-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多