首页 > 解决方案 > ViewPagerAdapter 工具栏可水平滚动

问题描述

我有一个带有许多选项卡的工具栏,但是当标签太多时,内部的文本被拆开,所有标签都在我的屏幕上。我希望我的工具栏可以滚动,但我自己不能这样做。

有我的布局:

<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <com.google.android.material.appbar.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay"
        >

        <androidx.appcompat.widget.Toolbar
            android:id="@+id/toolbar"
            android:scrollbars="horizontal"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay"
            app:layout_scrollFlags="scroll|enterAlways"

            />
    </com.google.android.material.appbar.AppBarLayout>

    <include layout="@layout/content_main" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>

我试图用 NestedScrollView 替换 appbarlayout 但不起作用。谢谢你的帮助。


在此处输入图像描述

您可以看到选项卡的名称被拆分,因为选项卡太多。我希望将工具栏的大小调整为选项卡,并且无法在 tabLayout 中水平滚动。

标签: androidxmlandroid-layout

解决方案


推荐阅读