I have a LinearLayout that I want to hide when I view my RecyclerView and reappear when scrolling down; the behavior should be similar to how the toolbar hides and reappears.
This is what I have so far:
<android.support.design.widget.CoordinatorLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <LinearLayout android:id="@+id/viewToHideOnScroll android:layout_width="match_parent" android:layout_height="wrap_content"> </LinearLayout> <RecyclerView android:id="@+id/recyclerView android:layout_width="match_parent" android:layout_height="wrap_content"/> </android.support.design.widget.CoordinatorLayout>
From what I can understand so far, I can specify the value of app:layout_behavior on viewToHideOnScroll so that it scrolls scrolls smoothly and does not display according to scroll events on recyclerView . To do this, I need to write my own ViewToHideOnScrollBehavior class and override layoutDependsOn and another method ( onNestedScroll ?).
If this is correct, here is what I have:
public class ViewToHideOnScrollBehavior extends CoordinatorLayout.Behavior<LinearLayout> { public ViewToHideOnScrollBehavior(Context context, AttributeSet attrs) {} @Override public boolean layoutDependsOn(CoordinatorLayout parent, LinearLayout child, View dependency) { return dependency instanceof RecyclerView; }
Can someone give me a hint, or am I doing it all wrong?
I followed https://lab.getbase.com/introduction-to-coordinator-layout-on-android/
source share