【问题标题】:How to provide overflow pagination in android tab layout?如何在android选项卡布局中提供溢出分页?
【发布时间】:2016-06-26 10:07:03
【问题描述】:

根据材料设计指南,在 android.support.design.widget.TabLayout 中,当有许多选项卡无法适应屏幕大小时,我们可以使用溢出分页,通过提供一个右箭头,单击该箭头将显示所有剩余的选项卡通过水平滚动。如何实现这一点?

[这是指南中给出的相同图像]

【问题讨论】:

    标签: android android-viewpager material-design android-support-library android-tablayout


    【解决方案1】:

    该模式位于“桌面标签”部分,因此不被 TabLayout 支持,它专门针对“移动标签”部分。

    【讨论】:

    • 如果您希望看到添加功能,请随时通过b.android.com 提交功能请求!
    • 嗨,谢谢你的回答,我不知道 TabLayout 不支持这个,我也想知道,如果在手机中有大约 8 个标签是一种糟糕的设计实践一次只有 4 个选项卡适合屏幕宽度。
    • 滚动标签(就像您需要 8 个标签一样)通常最适合将内容分类(想想音乐流派等)到多个同级中。我不会使用 8 个选项卡在您的应用中导航 - 这在导航抽屉中更合适,它可以更好地扩展到更多项目。
    • 我认为发生溢出时需要箭头支持。它将帮助用户看到更多内容。
    【解决方案2】:

    您必须在 XML 文件中将 tabMode 设置为可滚动

            <android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:tabMode="scrollable"/>
    

    【讨论】:

      【解决方案3】:

      无法添加分页箭头,但能够向 tabview 添加滚动:

      用 Horizo​​ntalScrollView 和 LinearLayout 包围你的 tabview:

      <HorizontalScrollView
                          android:id="@+id/scrollView1"
                          android:layout_width="match_parent"
                          android:layout_height="match_parent"
                          android:fillViewport="true"
                          android:layout_weight="1"
                          android:fadingEdgeLength="20dp"
                          android:scrollbars="none" >
                          <LinearLayout
                              android:layout_width="match_parent"
                              android:layout_height="wrap_content">
                          <android.support.design.widget.TabLayout
                              android:id="@+id/tabLayout"
                              android:layout_width="match_parent"
                              android:layout_height="wrap_content"
                              android:minHeight="?actionBarSize"
                              app:tabGravity="fill"
                              app:tabIndicatorColor="@color/white"
                              app:tabIndicatorHeight="4dp"
                              app:tabBackground="@color/colorPrimary"
                              app:tabMode="scrollable"
                              android:overScrollMode="never"
                              android:visibility="visible">
                          </android.support.design.widget.TabLayout>
                          </LinearLayout>
                      </HorizontalScrollView>
      

      【讨论】:

        猜你喜欢
        • 2016-12-06
        • 2023-04-01
        • 2018-06-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多