Recyclerview滚动不适用于嵌套滚动视图中的片段

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

首先:我以前使用回收器视图和滚动侦听器,一切都很好,但这是第一次使用协调器布局并在嵌套滚动视图中使用片段,所以我认为与设计有关的问题

这是我的滚动代码摘要

  categoryRecyclerView?.addOnScrollListener(object : RecyclerView.OnScrollListener() {

        override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
            super.onScrolled(recyclerView, dx, dy)
            Log.e("scrolling","scroll")
            if (dy > 0) {
                Log.e("scrolling","vertical")

因此,当我滚动时,无论我是否滚动,我都不会在logcat中看到(“ scrolling”,“ vertical”),但我只会看到(“ scrolling”,“ scroll”)一次)

这是我的活动xml

<?xml version="1.0" encoding="utf-8"?>

<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:background="@color/layoutBackground">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?actionBarSize"
            app:layout_scrollFlags="scroll|enterAlways"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
    </android.support.design.widget.AppBarLayout>

    <android.support.v4.widget.NestedScrollView
        android:id="@+id/nestedScroll"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:clipToPadding="false"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <FrameLayout
            android:padding="8dp"
            android:id="@+id/fragmentContainer"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

    </android.support.v4.widget.NestedScrollView>

    <android.support.design.widget.BottomNavigationView
        android:id="@+id/bottomNavigationView"
        android:layout_width="match_parent"
        android:layout_height="56dp"
        android:layout_gravity="bottom"
        android:background="@color/colorPrimary"
        android:padding="8dp"
        app:layout_behavior="@string/hide_bottom_view_on_scroll_behavior"
        app:itemIconTint="@drawable/navigation_item_selector"
        app:itemTextColor="@android:color/white"
        app:menu="@menu/navigation_menu" />

</android.support.design.widget.CoordinatorLayout>

这是我的片段xml

<?xml version="1.0" encoding="utf-8"?>

    <android.support.constraint.ConstraintLayout
        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"
        android:background="@color/layoutBackground"
        tools:context=".fragments.AllItemsFragment">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/categoryRecyclerView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            tools:listitem="@layout/entertainment_recycler_view_item" />

        <ProgressBar
            android:id="@+id/loadingCategoryList"
            style="?android:attr/progressBarStyle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

    </android.support.constraint.ConstraintLayout>

在我设置的片段中的onActivtyCreated中

scrollView.isNestedScrollingEnabled = false

并且在init recyclerview代码中,我将recyclerview设置为

categoryRecyclerView?.isNestedScrollingEnabled = false
categoryRecyclerView?.setHasFixedSize(false);

首先,我以前在回收器视图和滚动侦听器上工作,一切都很棒,但这是第一次使用协调器布局并在嵌套滚动视图中使用片段,所以我认为...

android android-recyclerview fragment android-coordinatorlayout nestedscrollview
1个回答
0
投票

设置

© www.soinside.com 2019 - 2024. All rights reserved.