0

I'm trying to get access to every touch event on the screen while a user is scrolling through a ScrollView so I can record the rawX, rawY, pressure, orientation and major and minor axis of the touch point. I currently am able to get access to the ACTION_DOWN by using an onTouchListener on a TextView inside the ScrollView. However, subsequent events are not being passed to the TextView.

I only need to monitor the event values of the pointer but I don't want to change any of the functionality of the ScrollView.

Is there anyway I can get access to these events?

kriti
  • 23
  • 6

2 Answers2

0

You can use getScrollY() and getScrollX() methods.

scrollView.getViewTreeObserver().addOnScrollChangedListener(new OnScrollChangedListener() {
    @Override
    public void onScrollChanged() {
        // for normal ScrollView
        int scrollY = rootScrollView.getScrollY(); 
        // for HorizontalScrollView
        int scrollX = rootScrollView.getScrollX(); 
    }
});
Onur A.
  • 3,007
  • 3
  • 22
  • 37
  • what is rootScrollView here? I think this is assuming that I have 2 scroll views, 1 for horizontal and 1 for vertical. I'm only using one ScrollView in the vertical direction and I need to record the touch points of the finger wherever it is on the screen – kriti Mar 04 '18 at 00:42
  • 1
    I assumed you are using nested scroll views hence I put rootScrollView as well. I also put horizontal change as you ask for rawX too. If you want ot capture only points on screen rather than scroll amount you can refer to this link https://stackoverflow.com/a/30579203/1936366 – Onur A. Mar 04 '18 at 14:14
0

I used an OnTouch Listener on the ScrollView in order to record the touch events data (getX, getY, etc) but also called the ScrollViews onTouchEvent from within it. I'm not sure if it is the best way to go about it but for my purposes it worked.

kriti
  • 23
  • 6