space below collapsing toolbar layout content on scrolling in side Coordinator Layout

44 views Asked by At

enter image description here

I'm currently working on an Android project where I've implemented a scrolling layout using a CoordinatorLayout. The layout consists of a fixed header, collapsible content, a TabLayout, and a ViewPager containing fragments with RecyclerViews.

My objective is to achieve a specific scrolling behavior:

When a user starts scrolling, the content within the CollapsingToolbarLayout should scroll first. After that, I want the TabLayout to remain fixed just below the header. Finally, the RecyclerView in the fragments should start scrolling. I've managed to set up this behavior, and it works well but not every time. However, I'm encountering an intermittent issue. Occasionally, when I open and close the activity multiple times, a mysterious white space appears below the appbar layout. This space has a height similar to that of the collapsible content.

I've thoroughly reviewed my code and layout setup, but I can't seem to identify the source of this issue. It's quite perplexing as it only occurs sporadically.

Has anyone experienced a similar problem or can provide insights into what might be causing this issue? Your expertise and guidance would be greatly appreciated.

Thank you in advance for your help!

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:id="@+id/parent">
<RelativeLayout
android:id="@+id/head"
android:layout_width="match_parent"
android:layout_height="@dimen/_45sdp"
android:paddingRight="@dimen/_7sdp"
android:background="@color/bg_light_color"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent">
<RelativeLayout
android:id="@+id/back"
android:layout_width="@dimen/_40sdp"
android:layout_height="@dimen/_35sdp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:paddingHorizontal="@dimen/_10sdp">
<ImageView
android:layout_width="@dimen/_16sdp"
android:layout_height="@dimen/_16sdp"
android:scaleType="fitXY"
android:layout_centerInParent="true"
android:src="@drawable/ic_back"
app:tint="@color/black"></ImageView>
</RelativeLayout>
<TextView
android:id="@+id/uname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="@+id/back"
android:textColor="@color/lightblack"
android:textSize="@dimen/_16sdp"
android:textStyle="bold"></TextView>
<RelativeLayout
android:id="@+id/notification"
android:layout_width="@dimen/_22sdp"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginTop="@dimen/_4sdp"
android:layout_marginRight="@dimen/_4sdp"
android:layout_toLeftOf="@+id/menu">
<ImageView
android:layout_width="@dimen/_21sdp"
android:layout_height="@dimen/_31sdp"
android:layout_centerInParent="true"
android:paddingTop="@dimen/_5sdp"
android:scaleType="fitXY"
android:src="@drawable/noun_notification_icon1"></ImageView>
</RelativeLayout>
<RelativeLayout
android:id="@+id/menu"
android:layout_width="@dimen/_19sdp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginLeft="@dimen/_8sdp"
android:layout_marginRight="@dimen/_4sdp"
android:padding="@dimen/_2sdp">
<ImageView
android:layout_width="@dimen/_17sdp"
android:layout_height="@dimen/_16sdp"
android:scaleType="fitXY"
android:src="@drawable/ic_dots__2_"></ImageView>
</RelativeLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/head"
android:visibility="gone"
android:id="@+id/main_rl">
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:nestedScrollingEnabled="true"
android:background="@color/white">
<com.google.android.material.appbar.CollapsingToolbarLayout
android:id="@+id/collapsingToolbarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RelativeLayout
android:id="@+id/profile_ll"
android:layout_height="wrap_content"
android:padding="@dimen/_7sdp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/head">
<de.hdodenhof.circleimageview.CircleImageView
xmlns:app="http://schemas.android.com/apk/res-auto"
 android:id="@+id/uimg"
android:layout_width="@dimen/_64sdp"
android:layout_height="@dimen/_64sdp"
android:layout_alignParentTop="true"
android:transitionName="profileImageTransition"
android:layout_marginTop="@dimen/_3sdp"
android:layout_marginLeft="@dimen/_6sdp"
android:src="@drawable/default_user" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="@dimen/_85sdp"
android:orientation="vertical">
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textColor="@color/lightblack"
android:textSize="@dimen/_16sdp"
android:textStyle="bold"></TextView>
<TextView
android:id="@id/bio"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textColor="@color/lightblack"
android:textSize="@dimen/_10sdp"></TextView>
</LinearLayout>
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/_85sdp"
android:paddingRight="@dimen/_7sdp"
android:orientation="horizontal"
android:weightSum="2">
<RelativeLayout
android:id="@+id/follow"
android:layout_width="0dp"
android:layout_height="@dimen/_25sdp"
android:layout_weight="1"
android:layout_marginRight="@dimen/_4sdp"
android:background="@drawable/rounded_btton_grey"
android:backgroundTint="@color/icon_orange">
<TextView
android:id="@+id/follow_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="Follow"
android:textColor="@color/lightblack"
android:textSize="@dimen/_12sdp"></TextView>
</RelativeLayout>
<RelativeLayout
android:id="@+id/message"
android:layout_width="0dp"
android:layout_height="@dimen/_25sdp"
android:layout_weight="1"
android:layout_marginLeft="@dimen/_2sdp"
android:background="@drawable/rounded_outline_grey"
android:backgroundTint="@color/lightblack">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="Message"
android:textColor="@color/lightblack"
android:textSize="@dimen/_12sdp"></TextView>
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="@dimen/_8sdp"
android:weightSum="3"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.8"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="@+id/post_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"
android:fontFamily="@font/robotobold"
android:textColor="@color/lightblack"
android:textSize="@dimen/_20sdp"></TextView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/_2sdp"
android:text="Posts"
android:textColor="@color/lightblack"
android:textSize="@dimen/_11sdp"></TextView>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1.4"
android:id="@+id/follower"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="@+id/follower_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"
android:fontFamily="@font/robotobold"
android:textColor="@color/lightblack"
android:textSize="@dimen/_20sdp"></TextView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/_2sdp"
android:text="Followers"
android:textColor="@color/lightblack"
android:textSize="@dimen/_11sdp"></TextView>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.8"
android:gravity="center"
android:id="@+id/following"
android:orientation="vertical">
<TextView
android:id="@+id/following_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"
android:fontFamily="@font/robotobold"
android:textColor="@color/lightblack"
android:textSize="@dimen/_20sdp"></TextView>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/_2sdp"
android:text="Following"
android:textColor="@color/lightblack"
android:textSize="@dimen/_11sdp"></TextView>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</com.google.android.material.appbar.CollapsingToolbarLayout>
<com.google.android.material.tabs.TabLayout
android:id="@+id/tab"
android:layout_width="match_parent"
android:layout_height="@dimen/_40sdp"
android:background="@color/white"
app:tabIconTint="@drawable/iconcolor_selector"
app:tabIndicatorColor="@color/icon_orange"
app:tabSelectedTextColor="@color/heading_color"
app:tabTextAppearance="@style/MineCustomTabText"
app:tabTextColor="@color/grey" />
</com.google.android.material.appbar.AppBarLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<androidx.viewpager.widget.ViewPager
android:id="@+id/pager"
android:layout_width="wrap_content"
android:layout_height="match_parent" />

</LinearLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</RelativeLayout>
<com.facebook.shimmer.ShimmerFrameLayout
android:id="@+id/shimmer_view_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="@dimen/_50sdp"
android:layout_gravity="center"
app:shimmer_duration="1000"
app:shimmer_highlight_alpha="0.5"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<include layout="@layout/profile_placeholder" />
</LinearLayout>
</com.facebook.shimmer.ShimmerFrameLayout>
</RelativeLayout>
0

There are 0 answers