Smooth horizontal scrolling in webview

I have a wevbiew with several “pages” (columns of text) in it and you want to be able to scroll horizontally between the columns in response to Fling gestures. I can do it perfectly using scrollTo (), but it is pretty sudden, and I would really like for you to smoothly move from one page to another.

The problem is what I see: you cannot attach a Scroller to a WebView and you must not embed a WebView in a ScrollView.

Does anyone have any good ideas for implementing smooth or animated horizontal scrolling in a WebView?

Edited to add: I'm trying to implement the knotmanish idea, where I use an unattached Scroller to calculate the distance.

    // vx and vy are from the onfling event of the gesture detector 
    scroller.fling(page*x, 0, vx, vy, page*(x + 1), page*(x + 1), 0, 0);

    while(scroller.computeScrollOffset()){
        webview.scrollTo(scroller.getCurrX(), 0);
        webview.invalidate();
    }

... but the while loop seems too slow to capture the movement of the scroller or something else, because the behavior looks just like the scrollTo () method (jump to the end of the scroll).

+3
source share
1 answer

You cannot attach a scroller to a web view, but you can use this gesture to do the same.

The gesture detects an outlier using this method.

onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY)

Give speed X, velocityY to the skeller method along with other parameters

fling(int startX, int startY, int velocityX, int velocityY, int minX, int maxX, int minY, int maxY)

scan the value of computeScrollOffset () to find the positions getCurrX (), getCurrY ().

- onTouchEvent (MotionEvent ev), dispatchTouchEvent (MotionEvent ev), false, -. gestureListener onfling, . . computeScrollOffset(), getCurrX() getCurrY() . , - .

, , - .

+4

Source: https://habr.com/ru/post/1795841/


All Articles