coordinatorlayout内的recyclerview无法正常工作

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

我在nestedscrollview中有一个recyclerview,并且nestedscrollview在coordinatorlayout中。在我的recyclerview上,将onTouchListener设置为向左滑动时会出现一些按钮。我的问题是我无法向左滑动recyclerview项目。因为向左滑动和向上滑动大约同时发生。

我尝试了recyclerView.setNestedScrollingEnabled(false)和app:layout_behavior =“ @ string / appbar_scrolling_view_behavior”

<androidx.coordinatorlayout.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true">

        <com.google.android.material.appbar.AppBarLayout
            android:id="@+id/app_bar_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            android:fitsSystemWindows="true">

            <com.google.android.material.appbar.CollapsingToolbarLayout
                android:id="@+id/collapsing_toolbar"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:layout_scrollFlags="scroll|exitUntilCollapsed"
                app:contentScrim="?attr/colorPrimary"
                app:expandedTitleMarginStart="48dp"
                app:expandedTitleMarginEnd="64dp"
                android:fitsSystemWindows="true">

                <fragment
                    android:id="@+id/map"
                    android:name="com.google.android.gms.maps.SupportMapFragment"
                    android:layout_width="match_parent"
                    android:layout_height="500dp"
                    android:fitsSystemWindows="true"
                    app:layout_collapseMode="parallax"
                    tools:context=".MainActivity" />

                <androidx.appcompat.widget.Toolbar
                    android:id="@+id/toolbar"
                    android:layout_width="match_parent"
                    android:layout_height="?attr/actionBarSize"
                    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                    app:layout_collapseMode="pin" />

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

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

        <androidx.core.widget.NestedScrollView
            android:id="@+id/scroll"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:clipToPadding="false"
            app:layout_behavior="@string/appbar_scrolling_view_behavior">

            <FrameLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <androidx.recyclerview.widget.RecyclerView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:nestedScrollingEnabled="false"
                    android:overScrollMode="never"/>
            </FrameLayout>

        </androidx.core.widget.NestedScrollView>

        <com.google.android.material.floatingactionbutton.FloatingActionButton
            android:id="@+id/fab"
            app:layout_anchor="@id/app_bar_layout"
            app:layout_anchorGravity="bottom|right|end"
            style="@style/FabStyle"/>

    </androidx.coordinatorlayout.widget.CoordinatorLayout>
android android-recyclerview android-coordinatorlayout
1个回答
-1
投票

用替换您的recyclerView,

<androidx.recyclerview.widget.RecyclerView
    android:id="@+id/recyclerView"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

这里,

app:layout_behavior="@string/appbar_scrolling_view_behavior"

将管理其余的事情。

另外一件事,无需将recyclerView放在NestedScrollView

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