Good afternoon I have a BottomSheetFragment which contains a ViewPager2 with multiple fragments inside. The ViewPager has horizontal scrolling between fragments, but content scrolling within each fragment DOES NOT WORK.
layout BottomSheetFragment:
<androidx.coordinatorlayout.widget.CoordinatorLayout
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">
<androidx.appcompat.widget.LinearLayoutCompat
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="@drawable/bg_bottom_sheet"
android:orientation="vertical">
<ImageView
android:layout_width="37dp"
android:layout_height="5dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dp"
android:layout_marginBottom="15dp"
android:src="@drawable/shape_gray" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rvAnalyticsTabs"
android:layout_width="match_parent"
android:layout_height="32dp"
android:layout_marginHorizontal="12dp"
android:layout_marginBottom="8dp"
android:background="@drawable/bg_default_tab"
android:clipToPadding="false"
android:orientation="horizontal"
android:padding="2dp"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:listitem="@layout/item_analytics_event_tab" />
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/viewPager"
android:layout_marginBottom="200dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</androidx.appcompat.widget.LinearLayoutCompat>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
Fragment layout inside ViewPager2 :
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white" />
<WebView
android:id="@+id/wvAnalytic"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:isScrollContainer="true" />
</FrameLayout>
Inside the fragment, in the onViewCreated method:
val behavior = BottomSheetBehavior.from(requireView().parent as View)
behavior.state = BottomSheetBehavior.STATE_COLLAPSED