I'm having a lot of problems with scrolling and detection of it inside fragments using coordinatorLayout in Android. I have a "Main Activity" that has inside it 3 fragments. Only on one of those fragments I want to have Appbar that collapses when fragment is scrolled. I've managed to do that, but if i set scrolling beahivour to allow that, my bottomNavigationView (which is found in mainactivity.xml) does NOT react to scrolling. Codes go something like this:
Fragment1.xml
<android.support.design.widget.CoordinatorLayout
...
.../>
<android.support.design.widget.AppBarLayout
...
.../>
<android.support.design.widget.CollapsingToolbarLayout
app:layout_scrollFlags="scroll|exitUntilCollapsed"
...>
<android.support.v7.widget.Toolbar
.../>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
app:layout_behavior="@string/appbar_scrolling_view_behavior"
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
MainActivity.xml
<android.support.design.widget.CoordinatorLayout
.../>
<FrameLayout
app:layout_behavior="@string/appbar_scrolling_view_behavior"
.../>
<android.support.design.widget.BottomNavigationView
app:layout_behavior="@string/hide_bottom_view_on_scroll_behavior"
.../>
</android.support.design.widget.CoordinatorLayout>
Now, this works well enough, in the sense that when i scroll inside fragment my AppBar collapses into the title (what i want), BUT my bottomNavigationView does not react to scrolling.
What i found out is that if i add the line
app:layout_behavior="@string/appbar_scrolling_view_behavior"
to the AppBarLyout xml declaration i get the bottomView to collapse on scroll event (when i scroll up it shows again). So basically either i have the ability to collapse appbar inside fragment OR i have the ability to hide BottomNavigationView when i detect a scroll event in fragment.
Any sort of help would be appreciated, I'm losing my mind over this for 3 straight days.