I am trying set three different fragments in ViePager2, inside a ScrollView, all three Fragments has a same RecyclerView, which are product lists with different heights, I am looking for a help to set the height of these RecyclerViews dynamically.
Activity.xml
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">...//some_code_here
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true">...//some_code_here
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/viewpager2"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</RelativeLayout>
</ScrollView>
</RelativeLayout>
Fragment.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_top_sale"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:nestedScrollingEnabled="false" />
</RelativeLayout>
</FrameLayout>
RecyclerView.xml
<RelativeLayout 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="wrap_content">
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:background="@color/colorWhite"
app:cardBackgroundColor="@color/colorWhite"
app:cardCornerRadius="8dp">
...//some_code_here
</androidx.cardview.widget.CardView>
</RelativeLayout>