ViewPager2与SwipeRefreshLayout冲突

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

我正在使用其中包含4个片段的Horizo​​ntal ViewPager2。每个片段在RecyclerView上都有SwipeRefreshLayout。我面临的问题是,当RecyclerView位于最高位置时,onClick在任何项目列表上都无法正常工作。如果我稍微向下滚动RecyclerView,则onClick可以正常工作。当RecyclerView处于最高位置时,如果SwipeRefreshLayout处于刷新状态,则onClick可以正常工作。似乎SwipeRefreshLayout在触摸事件中与ViewPager2冲突。使用简单的ViewPager可以正常工作。实际问题可能是什么,我们该如何处理?任何想法都是可取的。

谢谢

xml:

<androidx.constraintlayout.widget.ConstraintLayout
            android:id="@+id/fragment_home"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            >

            <include
                android:id="@+id/headerPanel"
                layout="@layout/home_header"
                app:viewModel="@{viewModel}" />

            <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
                android:id="@+id/swipe_refresh_layout"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:paddingStart="@dimen/home_post_side_spacing"
                android:paddingEnd="@dimen/home_post_side_spacing"
                app:colorScheme="@{@color/fayvo_color}"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/headerPanel"
                app:onRefreshListener="@{() -> viewModel.manualRefresh()}"
                app:refreshing="@{viewModel.isRefreshing}"
                android:background="#f0f0f0">

                <RelativeLayout
                    android:id="@+id/rl_rv"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">

                    <androidx.recyclerview.widget.RecyclerView
                        android:id="@+id/rv_homePosts"
                        adapter="@{viewModel.postObservableArrayList}"
                        addToTop="@{viewModel.addToTop}"
                        clearList="@{viewModel.clearList}"
                        showLoader="@{viewModel.isPagingEnabled &amp;&amp; viewModel.isLoading}"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />

                    <FrameLayout
                        android:id="@+id/emptyFrameLayout"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:visibility="@{viewModel.showEmptyLayout?View.VISIBLE:View.GONE}" />

                    <include
                        android:id="@+id/postUploadProgressLayout"
                        layout="@layout/item_post_upload_progress"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        app:viewModel="@{viewModel}" />

                </RelativeLayout>
            </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>


            <View
                android:id="@+id/tooltipView"
                android:layout_width="1dp"
                android:layout_height=".1dp"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                />
        </androidx.constraintlayout.widget.ConstraintLayout>
android android-recyclerview android-viewpager swiperefreshlayout android-viewpager2
1个回答
0
投票

我也面临相同的问题,这是由于嵌套滚动。经过大量搜索之后,我知道协调器布局应该用作父布局。还需要添加应用栏,然后它应该可以正常工作。它解决了问题。

<androidx.coordinatorlayout.widget.CoordinatorLayout
    android:id="@+id/coordinateLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.google.android.material.appbar.AppBarLayout
        android:id="@+id/fragmentAppBar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@null"
        app:elevation="0dp" />

    <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
        android:id="@+id/swipeLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        >

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/rvMemberList"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
            tools:listitem="@layout/holder_member_item" />

    </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
© www.soinside.com 2019 - 2024. All rights reserved.