title: Custom Toolbar overlapping Fragment
body: <p>So basically i'm trying to set a fragment up so that it shows my badges and for some reason it just won't fit the screen and starts from the top. It seems this results in the toolbar floating over the whole fragment. Is there something i'm doing wrong that anyone can point out? I'm using three fragments with a tabbing system.</p>
  
  <p><a href="https://i.stack.imgur.com/VO7fy.jpg" rel="nofollow noreferrer">Here is the screenshot</a></p>
  
  <p>1) Fragment (myFragment.java)</p>
  
  <pre><code>public class myFragment extends Fragment {
  
  
  public myFragment() {
      // Required empty public constructor
  }
  private RecyclerView recyclerView;
  private badgeAdapter adapter;
  private List&lt;hatBadge&gt; badge;
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
                           Bundle savedInstanceState) {
  
      final View view = inflater.inflate(R.layout.fragment_my_closet, container, false);
      final FragmentActivity c = getActivity();
      final RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.recycler_view);
  
      badge = new ArrayList&lt;&gt;();
  
      adapter = new badgeAdapter(getContext(), badge);
  
      RecyclerView.LayoutManager mLayoutManager = new GridLayoutManager(getContext(), 2);
      recyclerView.setLayoutManager(mLayoutManager);
      recyclerView.addItemDecoration(new myFragment.GridSpacingItemDecoration(2, dpToPx(10), true));
      recyclerView.setItemAnimator(new DefaultItemAnimator());
      new Thread(new Runnable() {
          @Override
          public void run() {
              c.runOnUiThread(new Runnable() {
                  @Override
                  public void run() {
                      recyclerView.setAdapter(adapter);
  
                  }
              });
          }
      }).start();
  
      prepareAlbums();
  
      return view;
  }
  /**
   * Adding few albums for testing
   */
  private void prepareAlbums() {
      int[] covers = new int[]{
              R.drawable.nike,
              R.drawable.nike,
              R.drawable.nike,
              R.drawable.nike};
  
      hatBadge a = new hatBadge("Hat 1", 13, covers[0]);
      badge.add(a);
  
      a = new hatBadge("Hat 1", 8, covers[1]);
      badge.add(a);
  
      a = new hatBadge("Hat 5", 11, covers[2]);
      badge.add(a);
  
      a = new hatBadge("Hat 5", 11, covers[2]);
      badge.add(a);
  
  
      adapter.notifyDataSetChanged();
  }
  
  /**
   * RecyclerView item decoration - give equal margin around grid item
   */
  public class GridSpacingItemDecoration extends RecyclerView.ItemDecoration {
  
      private int spanCount;
      private int spacing;
      private boolean includeEdge;
  
      public GridSpacingItemDecoration(int spanCount, int spacing, boolean includeEdge) {
          this.spanCount = spanCount;
          this.spacing = spacing;
          this.includeEdge = includeEdge;
      }
  
      @Override
      public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
          int position = parent.getChildAdapterPosition(view); // item position
          int column = position % spanCount; // item column
  
          if (includeEdge) {
              outRect.left = spacing - column * spacing / spanCount; // spacing - column * ((1f / spanCount) * spacing)
              outRect.right = (column + 1) * spacing / spanCount; // (column + 1) * ((1f / spanCount) * spacing)
  
              if (position &lt; spanCount) { // top edge
                  outRect.top = spacing;
              }
              outRect.bottom = spacing; // item bottom
          } else {
              outRect.left = column * spacing / spanCount; // column * ((1f / spanCount) * spacing)
              outRect.right = spacing - (column + 1) * spacing / spanCount; // spacing - (column + 1) * ((1f /    spanCount) * spacing)
              if (position &gt;= spanCount) {
                  outRect.top = spacing; // item top
              }
          }
      }
  }
  
  /**
   * Converting dp to pixel
   */
  private int dpToPx(int dp) {
      Resources r = getResources();
      return Math.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, r.getDisplayMetrics()));
  }
  
  }
  </code></pre>
  
  <p>2) Activity running Fragment (myActivity.java)</p>
  
  <pre><code>public class myActivity extends ActionBarActivity {
  
  Toolbar toolbar;
  TabLayout tabLayout;
  ViewPager viewPager;
  ViewPagerAdapter viewPagerAdapter;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  
      //Remove title bar
      this.requestWindowFeature(Window.FEATURE_NO_TITLE);
      this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
  
      setContentView(R.layout.activity_tab);
  
      toolbar = (Toolbar)findViewById(R.id.toolBar);
      setSupportActionBar(toolbar);
      tabLayout = (TabLayout)findViewById(R.id.tabLayout);
      viewPager = (ViewPager)findViewById(R.id.viewPager);
      viewPagerAdapter = new ViewPagerAdapter(getSupportFragmentManager());
      viewPagerAdapter.addFragments(new homeFragment(), "Info");
      viewPagerAdapter.addFragments(new myFragment(), "my Fragment");
      viewPagerAdapter.addFragments(new careFragment(), "Care");
      viewPager.setAdapter(viewPagerAdapter);
      tabLayout.setupWithViewPager(viewPager);
  
  }
  </code></pre>
  
  <p>3) fragment_my_closet.xml</p>
  
  <pre><code>&lt;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:background="@color/viewBg"
  &gt;
  
      &lt;android.support.v7.widget.RecyclerView
          android:id="@+id/recycler_view"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:scrollbars="vertical"
          android:clipToPadding="false" /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>4) Activity_tab.xml</p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout
      xmlns:app="http://schemas.android.com/apk/res-auto"
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent" android:layout_height="match_parent"&gt;
  
      &lt;android.support.design.widget.AppBarLayout
          android:layout_height="wrap_content"
          android:layout_width="match_parent"
          app:theme="@style/AppTheme"
          &gt;
          &lt;include
              android:layout_height="wrap_content"
              android:layout_width="match_parent"
              layout="@layout/toolbar_layout"
              /&gt;
          &lt;android.support.design.widget.TabLayout
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:id="@+id/tabLayout"
              app:tabMode="fixed"
              app:tabGravity="fill"
              &gt;&lt;/android.support.design.widget.TabLayout&gt;
  
  
      &lt;/android.support.design.widget.AppBarLayout&gt;
      &lt;android.support.v4.view.ViewPager
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:id="@+id/viewPager"
          &gt;&lt;/android.support.v4.view.ViewPager&gt;
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>5) toolbar_layout.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;android.support.v7.widget.Toolbar
  xmlns:app="http://schemas.android.com/apk/res-auto"
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent" android:layout_height="wrap_content"
  android:background="?attr/colorPrimaryDark"
  
  android:fitsSystemWindows="true"
  android:id="@+id/toolBar"
  app:theme="@style/Theme.AppCompat.Light.NoActionBar"&gt;
  
  &lt;/android.support.v7.widget.Toolbar&gt;
  </code></pre>