I have a layout that looks somewhat like this:
<FrameLayout>
<Scrollview (empty view, set GONE)>
<LinearLayout (loading screen, set GONE)>
<CoordinatorLayout>
<AppBarLayout>
<RelativeLayout scroll|enterAlways|enterAlwaysCollapsed>
</AppBarLayout>
<RecyclerView with layout_behavior set>
<NestedScrollView (variation of empty layout, set GONE)>
</CoordinatorLayout>
</FrameLayout>
In the AppBarLayout there is a horizontal RecyclerView with cells, then below the main RecyclerView contains a different kind of cell and scrolls vertically. This works great when scrolling - the AppBarLayout appears and disappears perfectly.
The problem comes when searching and limiting results in the two RecyclerViews. When either RecyclerView is empty, it should disappear - and so when the top horizontal RecyclerView is empty the whole AppBarLayout should disappear.
To achieve this, I am calling AppBarLayout.setExpanded(false)
- which is working. However, after calling that if I scroll the vertical RecyclerView up or down the AppBarLayout expands and shows itself. I've also tried resetting the LayoutParams scrollFlags so that they are 0, which should disable scrolling. The AppBarLayout no longer scrolls - but it still expands.
How can I totally prevent an AppBarLayout from expanding? I need to close it, and force it to stay closed until I reset it no matter what the user does.
In another place I had a scroll listener set up to expand the view at the top. This was triggering the expand where it should not have.