【问题标题】:Android: Scrollable tabsAndroid:可滚动的标签
【发布时间】:2012-11-22 18:11:15
【问题描述】:

我目前正在开发我的第一个 android 应用程序。我正在为我的应用程序使用选项卡式布局。我按照开发指南上的教程进行操作,但遇到了问题。本教程只使用了三个选项卡,但我需要更多。因此,标签会调整大小并聚集在一起。我希望有人能告诉我如何让它们滚动,就像在海豚浏览器中使用多个标签时一样。谢谢!

~亚伦

【问题讨论】:

    标签: android tabs


    【解决方案1】:

    使用 Yoel 所说的,只需添加: android:fillViewport="trueandroid:scrollbars="none"

    到 Horizo​​ntalScrollView 像这样:

        <HorizontalScrollView 
           android:id="@+id/horizontalScrollView1" 
           android:layout_width="fill_parent" 
           android:layout_height="wrap_content"
           android:fillViewport="true"
           android:scrollbars="none" >
    
           <TabWidget
               android:id="@android:id/tabs"
               android:layout_width="fill_parent"
               android:layout_height="wrap_content" />
    
        </HorizontalScrollView>
    

    【讨论】:

      【解决方案2】:

      我建议改为使用 HotizontalScrollView 包装 TabWidget。这样,您仍然可以按原样使用选项卡。

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

      请务必注意,如果您使用较少的选项卡,这将导致选项卡不会填满屏幕的整个宽度。我目前正在寻找解决此问题的方法。

      【讨论】:

        【解决方案3】:

        在这种情况下,您可能不想使用制表符。相反,您可以将所有“选项卡”放入屏幕顶部的水平线性布局中,像这样包裹在 ScrollView 中

        <?xml version="1.0" encoding="utf-8"?>
        <HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_height="wrap_content" android:layout_width="fill_parent">
            <LinearLayout 
                android:orientation="horizontal" android:layout_height="wrap_content"
                android:layout_width="fill_parent">
        
                ...buttons go here...
        
            </LinearLayout>
        </HorizontalScrollView>
        

        我认为这将为您提供所需的结果,但请告诉我

        【讨论】:

        • 编辑为使用 Horizo​​ntalScrollView 而不是 ScrollView(仅垂直滚动)
        • 谢谢。我将尝试以这种方式实现它并让您知道。
        猜你喜欢
        • 2011-05-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-11-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多