3

Im having a white space issue in my Recyclerview inside Scrolling activity. Please help me to resolve this problem. i have checked everything i have known such as no margins,paddings,tried by removing the FAB. but still the problem exists.

Having whitespace between Appbar and recyclerview

My XML code:

   <?xml version="1.0" encoding="utf-8"?>
<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:fitsSystemWindows="true"
   >

    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar"
        android:layout_width="match_parent"
        android:layout_height="@dimen/app_bar_height"
        android:fitsSystemWindows="true"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/toolbar_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/AppTheme.PopupOverlay" />

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

    <android.support.v7.widget.RecyclerView
        android:id="@+id/id_recyclerview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginRight="@dimen/fab_margin"
        android:src="@android:drawable/ic_dialog_email"
        app:layout_anchor="@id/app_bar"
        app:layout_anchorGravity="bottom|end" />

</android.support.design.widget.CoordinatorLayout>
Mr Robot
  • 1,747
  • 6
  • 35
  • 67
  • 2
    post your complete xml code, I can see some parts missing – Vivek Mishra Aug 29 '16 at 13:33
  • 2
    For me it looks like your height from AppBarLayout is bigger than the content and white space appears. Replace it with wrap content – mhenryk Aug 29 '16 at 13:33
  • @VivekMishra : added full XML code in question . – Mr Robot Aug 29 '16 at 14:02
  • @mhenryk: when i use wrap_content as layout height , the whole appbar disappears. – Mr Robot Aug 29 '16 at 14:04
  • 1
    Right, make sure your layout has the proper height. To me it looks like it misses a statusbar size. Check what happens if you remove "fitsSystemWindows" from CoordinatorLayout. Keep it in AppBar though. – mhenryk Aug 29 '16 at 14:05
  • 1
    The code you have mentioned seems alright. Need to check the RecyclerView's list item layout. – Chintan Soni Aug 29 '16 at 14:18
  • @ChintanSoni: if item layout had any problems, i guess the whitespace should come between every Recycler view item. So its not the problem of item Layout – Mr Robot Aug 29 '16 at 14:55
  • 1
    This problem is happening between the appbar and the recycler, doesnt seem to have anything to do with the wxh of them – TWL Aug 29 '16 at 15:01
  • Last thing to check is the theme you're using and support library version. Please check and revert back with comment. – Chintan Soni Aug 29 '16 at 15:51

3 Answers3

2

Try this by removing android:fitsSystemWindows="true" and android:layout_height="wrap_content"

<android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">
Uttam Panchasara
  • 5,735
  • 5
  • 25
  • 41
1

Try this :

<android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true"
        android:theme="@style/AppTheme.AppBarOverlay">
Burhanuddin Rashid
  • 5,260
  • 6
  • 34
  • 51
1

Atlast i figured it now, First of all,Thanks to TWL for giving me an idea by a same issue of his question .

I removed the android:fitsSystemWindows="true" from the CoordinatorLayout.

Now, your notification bar's color is probably change to Transparent and looks horrible. So, i have added <item name="android:statusBarColor" tools:targetApi="lollipop">@color/colorPrimary</item> in styles.

Now everything is Okay.

Community
  • 1
  • 1
Mr Robot
  • 1,747
  • 6
  • 35
  • 67
  • 1
    thank you, but if you notice now, your notification bar's color is probably not part of your app's theme color because it's no longer 'under', but 'below' it now. – TWL Aug 30 '16 at 17:16
  • @TWL : yes, i changed that too by adding `@color/colorPrimary` in styles – Mr Robot Aug 31 '16 at 07:40