Search code examples
androidandroid-actionbarandroid-scrollview

Detect if a ScrollView is scrolling up or down - Android


I have one ScrollView with one LinearLayout with TextViews. I want to detect when ScrollView is scrolling up or down to hide/show ActionBar.


Solution

  • you need to create a class that extends ScrollView

    public class ExampleScrollView extends ScrollView 
    

    and then Override onScrollChanged that gives you the old and new scroll positions and from there you can detect which direction

    protected void onScrollChanged(int l, int t, int oldl, int oldt)