【已解决】 ViewPager内嵌RecyclerView如何才能使整个屏幕随RecyclerView一起滑动?
整体布局效果是这样的:

我把Fragment布局代码和ViewPager内部的分开了
这是Fragment的布局,就包含了一个AppBar和整个页面的ViewPager
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/fragment_taotao_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/magic_indicator_wrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal">
<net.lucode.hackware.magicindicator.MagicIndicator
android:id="@+id/magic_indicator"
android:layout_width="wrap_content"
android:layout_height="45dp"
android:layout_marginBottom="5dp"
app:layout_scrollFlags="scroll|enterAlways|snap" />
</com.google.android.material.appbar.AppBarLayout>
<androidx.viewpager.widget.ViewPager
android:id="@+id/taotao_container_view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:overScrollMode="never"
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
下面是ViewPager内部的代码
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!--这个是下拉刷新组件-->
<com.scwang.smartrefresh.layout.SmartRefreshLayout
android:id="@+id/refresh"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:srlEnableNestedScrolling="true"
app:srlFooterMaxDragRate="2"
app:srlHeaderMaxDragRate="1.7">
<!--这个也是下拉刷新组件的一部分-->
<com.example.schoolairdrop.ui.components.refresher.DeliveryHeader
android:id="@+id/delivery"
android:layout_width="match_parent"
android:layout_height="80dp" />
<!--这里又有一层LinearLayout是由于这个下拉刷新组件最多只能有3个直接子View-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<Button
android:id="@+id/taotao_search_view"
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginStart="@dimen/x12"
android:layout_marginTop="@dimen/taotao_fragment_general_margin_end_start"
android:layout_marginEnd="@dimen/x12"
android:background="@drawable/search_view_background"
android:text="@string/search_view_hint"
android:textColor="@color/colorAlphaText" />
<!--这个是轮播图-->
<com.example.schoolairdrop.ui.components.my_view_pager.MyLooperPager
android:id="@+id/my_looper_pager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/taotao_fragment_general_margin_end_start"
android:layout_marginBottom="@dimen/taotao_fragment_general_margin_end_start" />
<!--这个是GridLayout-->
<GridLayout
android:id="@+id/taotao_activities_area"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/taotao_fragment_general_margin_end_start"
android:layout_marginTop="@dimen/taotao_fragment_general_margin_end_start"
android:layout_marginEnd="@dimen/taotao_fragment_general_margin_end_start"
android:background="@drawable/taotao_looper_pager_radius_rect"
android:columnCount="5"
android:rowCount="3">
</GridLayout>
<!-- 这个是下面的 RecyclerView,里面就是一个LinearLayout含一个RecyclerView -->
<include layout="@layout/component_good_goods_recycler_view" />
</LinearLayout>
</com.scwang.smartrefresh.layout.SmartRefreshLayout>
</LinearLayout>
我想象中的效果是RecyclerView滑动的时候整个页面会一起滑动,但实际上是RecyclerView局部滑动…
就是上面的轮播图、网格布局原地不动……但是RV里的item会滑动
是我的布局有问题吗
还是ViewPager里套的RecyclerView不能和整个屏幕一起滑动呢…
如果都不是的话我如何才能在滑动RecyclerView的时候让整个屏幕一起滑动
您的每一个用心回答,都会让这个世界变得更美好一些!