Here is xml of my layout having CollapsingToolbar and viewpager. I am using NestedScrollViews so that the CollapsingToolbarLayout, swipetoreferesh and viewpager work smoothly.
<layout 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">
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".wallet_staking_survey.ui.survey_main.SurveyMain2Fragment">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appBarlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<com.google.android.material.appbar.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:fitsSystemWindows="true"
app:contentScrim="@color/colorPrimary"
app:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:layout_width="match_parent"
android:layout_height="@dimen/_260sdp"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
android:src="@drawable/bg_kyc_progress_level"
app:layout_collapseMode="parallax" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical">
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="@dimen/_20sdp"
android:orientation="vertical">
<com.realresearch.survey.customviews.DonutProgress
android:id="@+id/levelProgress"
android:layout_width="@dimen/_180sdp"
android:layout_height="@dimen/_180sdp"
android:layout_gravity="center"
app:donut_background_color="@android:color/transparent"
app:donut_circle_starting_degree="270"
app:donut_finished_color="@color/md_light_green_300"
app:donut_finished_stroke_width="5dp"
app:donut_text=""
app:donut_unfinished_color="@color/md_grey_100"
app:donut_unfinished_stroke_width="5dp" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="@+id/tvLevel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/recipekorea"
android:text="@string/level_2"
android:textColor="@android:color/white"
android:textSize="@dimen/_24sdp" />
<LinearLayout
android:id="@+id/llKycLevelProgress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:orientation="horizontal">
<TextView
android:id="@+id/tvUpgradKyc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/_5sdp"
android:fontFamily="@font/recipekorea"
android:text="@string/try_updating_your_kyc_level"
android:textColor="@android:color/white"
android:textSize="@dimen/_14sdp" />
<ImageView
android:id="@+id/ivHelp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/_5sdp"
android:layout_marginStart="@dimen/_4sdp"
android:src="@drawable/ic_baseline_help_24"
android:text="@string/try_updating_your_kyc_level"
android:textColor="@android:color/white"
android:textSize="@dimen/_14sdp" />
</LinearLayout>
</LinearLayout>
</FrameLayout>
<androidx.cardview.widget.CardView
android:id="@+id/cv_wallet_balance"
android:layout_width="match_parent"
android:layout_height="@dimen/_60sdp"
android:layout_marginStart="@dimen/_30sdp"
android:layout_marginTop="@dimen/_230sdp"
android:layout_marginEnd="@dimen/_30sdp"
android:layout_marginBottom="@dimen/_10sdp"
app:cardCornerRadius="@dimen/_35sdp">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center">
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:fontFamily="@font/recipekorea"
android:text="@string/my_tnc"
android:textColor="@color/textColor"
android:textSize="@dimen/_16sdp" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/title">
<TextView
android:id="@+id/tvMyTNCBalance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/recipekorea"
android:gravity="center"
android:text="10,000"
android:textColor="@color/pinkRed"
android:textSize="@dimen/_20sdp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/_5sdp"
android:fontFamily="@font/recipekorea"
android:text="@string/tnc"
android:textColor="@color/md_grey_400" />
</LinearLayout>
</RelativeLayout>
</androidx.cardview.widget.CardView>
</com.google.android.material.appbar.CollapsingToolbarLayout>
<!--- ADD TAB_LAYOUT HERE-->
<com.google.android.material.tabs.TabLayout
android:id="@+id/surveyTabs"
android:layout_width="match_parent"
android:layout_height="40dp"
android:fillViewport="true"
app:tabGravity="fill"
app:tabMode="scrollable" />
</com.google.android.material.appbar.AppBarLayout>
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="fill_vertical"
android:clipToPadding="false"
android:fillViewport="true"
android:isScrollContainer="false"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/swipe_to_refresh"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.core.widget.NestedScrollView
android:id="@+id/horizontalScrollView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipToPadding="false"
android:fillViewport="true"
android:isScrollContainer="false">
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/surveyFilterPager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</androidx.core.widget.NestedScrollView>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</androidx.core.widget.NestedScrollView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</layout>
I am using single fragment having a recyclerview to show three fragments in viewpager i.e. FragmentA, FragmentB, and FragmentC. Now the problem is FragmentB takes height equals to the content of FragmentA resulting in empty scrollable spaces in FragmentB. Same is the case with FragmentC. Below is the xml of my Fragment having recyclerview.
<layout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="3">
<LinearLayout
android:id="@+id/ll_no_survey"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="@dimen/_50sdp"
android:gravity="center"
android:visibility="gone"
android:orientation="vertical">
<ImageView
android:layout_width="@dimen/_60sdp"
android:layout_height="@dimen/_60sdp"
android:src="@drawable/ic_info" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:fontFamily="@font/open_sans_semi_bold"
android:text="@string/no_survey_response"
android:textColor="@color/defaultTextColor"
android:textSize="17.3sp" />
</LinearLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/survey_recyclerview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:visibility="visible" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:fontFamily="@font/open_sans_semi_bold"
android:text="@string/all_surveys"
android:textColor="@color/c_0078AB"
android:textSize="17.3sp"
android:visibility="gone" />
</RelativeLayout>
</layout>
Please help me as i am not able to find any solution.
The second
NestedScrollView
seems to be unnecessary, you can try something like the following codes: