使用ViewPager2的折叠工具栏会出现滚动问题

问题描述 投票:0回答:1

所以我有一个奇怪的问题,只发生在我一直试图解决的ViewPager2上,但以前从未见过类似的报道。

我正在尝试将ViewPager2与ToolBar进行协调,以使其在用户滚动其中的内容时将其隐藏。当使用填充的RecyclerView加载片段时,它工作正常,但是当再循环者为空或根本没有片段时,它的行为很奇怪。

以下是一些gif来显示问题(第一个ViewPager2(错误),第二个ViewPager(正确))。

您可以在第一张图片中看到,只有当我选择工具栏,但是每当我抓住空白时都会出现拖动问题NestedScrollView所在的空间。

Gif of the ViewPager2Gif of the ViewPager

这是ViewPager2的xml布局:

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".MainActivity">

<com.google.android.material.appbar.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <androidx.appcompat.widget.Toolbar
        android:id="@+id/toolBar"
        style="@style/Widget.MaterialComponents.Toolbar"
        android:layout_width="match_parent"
        android:layout_height="?actionBarSize"
        app:layout_scrollFlags="scroll|enterAlways"/>

    <com.google.android.material.tabs.TabLayout
        android:id="@+id/tabLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        style="@style/Widget.MaterialComponents.TabLayout.Colored" >

        <com.google.android.material.tabs.TabItem
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Test" />

    </com.google.android.material.tabs.TabLayout>

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

<androidx.core.widget.NestedScrollView
    android:id="@+id/scrollView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <androidx.viewpager2.widget.ViewPager2
        android:id="@+id/viewPager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

</androidx.core.widget.NestedScrollView>

</androidx.coordinatorlayout.widget.CoordinatorLayout>
java android android-toolbar android-nestedscrollview
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.