1

Anyone know how to detect ScrollView direction because I have to show and hide ActionBar on scrolling? I can easily detect with help of listview but don't know about ScrollView.

Ashish Jain
  • 328
  • 2
  • 15
  • Can't you aware with `android:scrollbars`? Also _onScrollChanged_ method you can get `X` and `Y` values which indicates horizontal and vertical scrolling direction. Also use _CoordinateLayout_ – Piyush Oct 05 '16 at 08:21
  • Hope this will help. [http://stackoverflow.com/questions/10713312/can-i-have-onscrolllistener-for-a-scrollview](http://stackoverflow.com/questions/10713312/can-i-have-onscrolllistener-for-a-scrollview) – Harv Oct 05 '16 at 08:25
  • see `View#onScrollChanged(int l, int t, int oldl, int oldt)` – pskink Oct 05 '16 at 08:27
  • I have tried scrollView.setOnScrollChangeListener(new View.OnScrollChangeListener() { @Override public void onScrollChange(View view, int i, int i1, int i2, int i3) { } }); but when scroll fast then it's not giving proper Y value so my hide/show concept not working properly . – Ashish Jain Oct 05 '16 at 08:31

2 Answers2

0

you can extend the scrollView because scrollview doesnt have such listener. just extend the scrolView and call your callback from the overrided onScrollChanged method.

then in your xml file use your CustomScrollView like this:

<my.package.CustomScrollView>xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/my_view"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    />
Amir Ziarati
  • 14,248
  • 11
  • 47
  • 52
  • Don't [Copy-paste](http://stackoverflow.com/questions/7490377/get-scrolling-direction-in-a-scrollview) – Piyush Oct 05 '16 at 08:24
  • Thanks to reply. I have some concern like 1. Should I need to change HorizontalScrollView to VerticalScrollView because I have to detect direction vertically(up/down) ? 2. How to use CustomScrollView Class ? – Ashish Jain Oct 05 '16 at 08:28
-2

I think what you meant by scroll was detecting which direction, a swipe has been made . Here is an example

Nandhu
  • 158
  • 9