0

How to stop scroll ScrollView when show speicific view in ScrollView ?

         .....
         View2
----------------------------------
|                                |
|        View3                   |
|                                |
|                                |
|        View4                   |
|                                |
|                                | <------ It's Screen 
|        View5                   |
|                                |
|                                |
|        View6                   |
|                                |
|                                |
|        View7                   |
|                                |
|                                |
|        View8                   |
|                                |
|                                |
|        View9                   |
----------------------------------

         View10
         ......

How to catch moment when View9 is showed and stop scrolling.

1 Answers1

0

I never had to do this but here is what I would do.

First, you need to detect when your View9 is diplayed and visible. So I would use something like this

Rect scrollBounds = new Rect();
scrollView.getHitRect(scrollBounds);
if (imageView.getLocalVisibleRect(scrollBounds)) {
    // imageView is within the visible window
} else {
    // imageView is not within the visible window
} 

(from https://stackoverflow.com/a/12428208/3187128)

Try to execute this every X second to test the code.

Then, if you want something cleaner, you should use a scrollListener:

scrollView.getViewTreeObserver().addOnScrollChangedListener(new OnScrollChangedListener() {

    @Override
    public void onScrollChanged() {

        int scrollX = rootScrollView.getScrollX(); //for horizontalScrollView
        int scrollY = rootScrollView.getScrollY(); //for verticalScrollView
        //DO SOMETHING WITH THE SCROLL COORDINATES

    }
});

(from https://stackoverflow.com/a/23365539/3187128)

Last step would be to implement a custom scrollview to be able to disable the scrolling :

cf https://stackoverflow.com/a/5763815/3187128

Hope this will help :)

Community
  • 1
  • 1
Jejefcgb
  • 390
  • 3
  • 14