如何在 android 选项卡布局中提供溢出分页?

How to provide overflow pagination in android tab layout?

根据 Material 设计准则,在 android.support.design.widget.TabLayout 中,当有许多选项卡无法适应屏幕尺寸时,我们可以使用溢出分页,通过提供一个右箭头,单击该箭头时将显示所有通过滚动剩余标签 horizontally.How 来实现这个?

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

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

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

该模式位于 'Desktop tabs' 部分,因此不受 TabLayout 支持,后者专门针对 'Mobile tabs' 部分。

无法添加分页箭头但能够向 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>