Search code examples
javaandroidandroid-recyclerviewcoordinator-layout

CollapsingToolbarLayout leaving empty space below Recyclerview


I'm having this strange issue with CoordinatorLayout and RecyclerView.

As you can see in the image, the RecyclerView is leaving an empty blank space below it with the exact same height as declared for CollapsingToolbarLayout's minHeight attribute.

If I don't declare this attribute, the linear_navigation LinearLayout won't remain pinned to the top of the screen (and that's the desired behaviour).

I'm I missing something? Here's the layout's code and some screenshots.

<android.support.design.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">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar_profile"
        android:layout_width="match_parent"
        android:layout_height="@dimen/profile_header_height"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_header"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:minHeight="?attr/actionBarSize"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:background="@drawable/bg_welcome"
                android:orientation="vertical"
                app:layout_collapseMode="parallax">

                <com.tourwhiz.pro.widgets.TextViewComfortaaBold
                    android:id="@+id/text_username"
                    style="@style/TextViewTW.Title"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_margin="@dimen/view_size_normal"
                    android:gravity="center"
                    android:text="Juancho"
                    android:textSize="@dimen/text_size_medium" />

                <LinearLayout
                    android:id="@+id/linear_settings"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:gravity="center">

                    <ImageView
                        android:id="@+id/image_settings"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:src="@drawable/ic_settings_white" />

                    <de.hdodenhof.circleimageview.CircleImageView
                        android:id="@+id/image_user"
                        android:layout_width="@dimen/profile_image_radious"
                        android:layout_height="@dimen/profile_image_radious"
                        android:layout_margin="@dimen/view_size_normal"
                        android:src="@drawable/madrid_01"
                        app:civ_border_color="@color/karma_aqua_blue"
                        app:civ_border_width="@dimen/view_size_tiny" />

                    <ImageView
                        android:id="@+id/image_edit"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:src="@drawable/ic_mode_edit_white" />
                </LinearLayout>
            </LinearLayout>

            <LinearLayout
                android:id="@+id/linear_navigation"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="bottom"
                app:layout_collapseMode="pin"
                android:background="@color/white"
                android:orientation="horizontal">

                <LinearLayout
                    android:id="@+id/linear_posts"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:orientation="vertical"
                    android:padding="@dimen/view_size_normal">

                    <com.tourwhiz.pro.widgets.TextViewLatoRegular
                        style="@style/TextViewTW"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:gravity="center"
                        android:text="@string/profile_posts_text"
                        android:textSize="@dimen/text_size_large" />

                    <com.tourwhiz.pro.widgets.TextViewLatoRegular
                        android:id="@+id/text_posts_count"
                        style="@style/TextViewTW"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:gravity="center"
                        android:textSize="@dimen/text_size_large"
                        tools:text="1456" />

                </LinearLayout>

                <View
                    android:layout_width="@dimen/separator_height"
                    android:layout_height="match_parent"
                    android:layout_marginBottom="@dimen/text_size_normal"
                    android:layout_marginTop="@dimen/text_size_normal"
                    android:background="@color/dark_grey" />

                <LinearLayout
                    android:id="@+id/linear_friends"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:orientation="vertical"
                    android:padding="@dimen/view_size_normal">

                    <com.tourwhiz.pro.widgets.TextViewLatoRegular
                        style="@style/TextViewTW"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:gravity="center"
                        android:text="@string/profile_friends_text"
                        android:textSize="@dimen/text_size_large" />

                    <com.tourwhiz.pro.widgets.TextViewLatoRegular
                        android:id="@+id/text_friends_count"
                        style="@style/TextViewTW"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:gravity="center"
                        android:textSize="@dimen/text_size_large"
                        tools:text="1" />

                </LinearLayout>

                <View
                    android:layout_width="@dimen/separator_height"
                    android:layout_height="match_parent"
                    android:layout_marginBottom="@dimen/text_size_normal"
                    android:layout_marginTop="@dimen/text_size_normal"
                    android:background="@color/dark_grey" />

                <LinearLayout
                    android:id="@+id/linear_reviews"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:orientation="vertical"
                    android:padding="@dimen/view_size_normal">

                    <com.tourwhiz.pro.widgets.TextViewLatoRegular
                        style="@style/TextViewTW"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:gravity="center"
                        android:text="@string/profile_reviews_text"
                        android:textSize="@dimen/text_size_large" />

                    <com.tourwhiz.pro.widgets.TextViewLatoRegular
                        android:id="@+id/text_reviews_count"
                        style="@style/TextViewTW"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:gravity="center"
                        android:textSize="@dimen/text_size_large"
                        tools:text="12" />

                </LinearLayout>
            </LinearLayout>
        </android.support.design.widget.CollapsingToolbarLayout>
    </android.support.design.widget.AppBarLayout>

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recycler_posts"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="bottom"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        tools:listitem="@layout/item_post" />


</android.support.design.widget.CoordinatorLayout>

The blank bottom space is the problem


Solution

  • Finally I've found a workaround for my situation. I don't know exactly why it works, but it does. If somebody knows why this is working, or even better, why is it happening, please answer the question and I will be happy to accept the answer as correct.

    The workaround is placing an empty gone view below the RecyclerView. It's working for me!

                       ...
                   </LinearLayout>
                </LinearLayout>
            </android.support.design.widget.CollapsingToolbarLayout>
        </android.support.design.widget.AppBarLayout>
    
        <android.support.v7.widget.RecyclerView
            android:id="@+id/recycler_posts"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="bottom"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"
            tools:listitem="@layout/item_post" />
    
    
    </android.support.design.widget.CoordinatorLayout>
        <View
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:visibility="gone" />
    </android.support.design.widget.CoordinatorLayout>