【发布时间】:2020-03-21 13:57:58
【问题描述】:
所以我遇到了这个奇怪的问题,它只发生在我一直试图解决的 ViewPager2 上,但以前从未见过这样的报告。
我正在尝试将 ViewPager2 与 ToolBar 协调起来,以便在用户滚动其中的内容时使其隐藏。 它在加载带有填充 RecyclerView 的片段时工作正常,但在回收器为空或根本没有片段时表现奇怪。
这里有一些 gif 来显示问题(第一个 ViewPager2(错误),第二个 ViewPager(正确))。
正如您在第一张图片中看到的那样,它只有在我选择时才能正常工作 工具栏,但每当我抓住空的时候都会出现拖动问题 NestedScrollView 所在的空间。
这是 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