2

I'm trying to create a Collapsing Toolbar Layout using RecyclerLayout.

The problem is that, When I'm inflating the Layout during run time, it's adding a default padding on it's own.

Below are my layout xmls:

activity_profile.xml

<?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"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:fitsSystemWindows="true">

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

   <android.support.design.widget.AppBarLayout
      android:id="@+id/appbar"
      android:layout_width="match_parent"
      android:layout_height="180dp"
      android:fitsSystemWindows="true"
      android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

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

           <ImageView
               android:id="@+id/header"
               android:layout_width="match_parent"
               android:layout_height="match_parent"
               android:fitsSystemWindows="true"
               android:scaleType="centerCrop"
               app:layout_collapseMode="parallax" />

           <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/ThemeOverlay.AppCompat.Light" />

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

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

   <android.support.design.widget.FloatingActionButton
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:layout_margin="10dp"
       app:layout_anchor="@+id/appbar"
       app:layout_anchorGravity="bottom|center|end" />

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

I've tried to remove activity_horizontal_margin as well but it does not seem to work.

Here is the layout that I'm trying to inflate in the recycler-layout:

profile_view.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 
    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.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/colorProfileStatsBackground"      
        app:layout_constraintBottom_toTopOf="@+id/guideline">

    </android.support.constraint.ConstraintLayout>

    <android.support.constraint.Guideline
        android:id="@+id/guideline"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        app:layout_constraintGuide_percent="0.25" />

</android.support.constraint.ConstraintLayout>

Output:

Final Output

Reaz Murshed
  • 23,691
  • 13
  • 78
  • 98
Akshay Singh
  • 313
  • 1
  • 5
  • 16

1 Answers1

0

Finally figured out the problem.

The problem was with android:fitsSystemWindows="true" in AppBarLayout.

I did some research, and found an article fitsSystemWindow which decribes that the default behavior of this attribute is that it sets the padding of the View to ensure the contents don’t overlay the system windows.

Akshay Singh
  • 313
  • 1
  • 5
  • 16