Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Navigation Bar covering viewpager content

I can't stop the Systems Navigation Bar from covering up my content!

enter image description here

I am scrolled to the very bottom of the recyclerview but its getting hidden behind the navigation bar. Here is my XML layout.

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/root" android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true">  <android.support.design.widget.AppBarLayout     android:id="@+id/appbar"     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">      <include layout="@layout/toolbar"/>      <android.support.design.widget.TabLayout         android:id="@+id/tabs"         android:layout_width="match_parent"         android:layout_height="wrap_content" />  </android.support.design.widget.AppBarLayout>  <android.support.v4.view.ViewPager     android:fitsSystemWindows="true"     android:id="@+id/viewpager"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     app:layout_behavior="@string/appbar_scrolling_view_behavior" />  <com.melnykov.fab.FloatingActionButton     android:id="@+id/fab"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_gravity="bottom|right"     android:layout_margin="16dp"     app:fab_colorNormal="@color/accent"     app:fab_colorPressed="@color/accent_dark" /> 

Here is the fragments layout which you are seeing in the picture.

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:padding="8dp">  <android.support.v7.widget.RecyclerView     android:id="@+id/recyclerView"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:scrollbars="vertical"/>  </FrameLayout> 

Ive tried adding android:fitsSystemWindows="true" into every piece of layout I could but that did not work. Other threads mention adding margin calculated from the bar, but that doesn't seem like the proper solution. I grabbed this layout directly from Google's CheesSquare app demo'ing the appbarlayout, and that one looks like its working fine.

like image 327
Nick H Avatar asked Jun 12 '15 01:06

Nick H


Video Answer


2 Answers

I Figured it out. In my particular situation each of my fragments manage their own toolbar instance. I was calling setSupportActionBar() in the onViewCreated() method on my fragments. Moving this functionality into onCreateView() solved it.

    @Nullable     @Override     public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {         View view = inflater.inflate(R.layout.fragment_my_account, container, false);         setupToolbar((Toolbar) view.findViewById(R.id.toolbar));         return view;     }      private void setupToolbar(Toolbar toolbar) {         toolbarController.registerToolbar(toolbar);         toolbarController.setActivityTitle("My Account");     } 

(registerToolbar() calls setSupportActionBar() inside the hosting activity).

Hope this helps everyone!

like image 89
Nick H Avatar answered Sep 19 '22 12:09

Nick H


Viewpager's fragment root view has to be RecyclerView or NestedScrollView. FrameLayout doesn't support scrolling behavior of CoordinatorLayout and this is why it doesn't work well.

How you can fix the viewpager's fragment layout: don't wrap RecyclerView inside FrameLayout. Instead declare RecyclerView at the root. You also can set padding="8dp" on RecyclerView, just use android:clipToPadding="false".

like image 39
Dima Kornilov Avatar answered Sep 18 '22 12:09

Dima Kornilov