本文介绍了在网页视图平滑水平滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有许多的页它(文字列)一个wevbiew,并希望能够在响应列之间水平滚动甩手势。我所能做的使用scrollTo()这个很好,但是这是比较突然,我真的希望能够从一个页下做的平稳过渡。

I have a wevbiew with a number of 'pages' (columns of text) in it, and want to be able to scroll horizontally between columns in response to Fling gestures. I can do this fine using scrollTo(), but that is rather sudden and I'd really like to be able to do a smooth transition from one 'page' to the next.

在我看来这个问题:你不能附加一个滚轮,一个web视图,并且不应该嵌套的WebView在滚动型。

The problem as I see it: you can't attach a Scroller to a WebView, and shouldn't nest a WebView in a ScrollView.

有没有人有一个web视图实现平稳或动画水平滚动什么好的建议?

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

编辑补充:我想实现knotmanish的,我用一个独立的滚轮来计算距离的想法..

Edited to add: I'm trying to implement an idea of knotmanish's where I use an unattached Scroller to compute 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();
    }

...但while循环似乎太慢捕捉滚轮运动,或东西,因为行为看起来就像scrollTo()方法(视图跳转到滚动的末尾)。

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

推荐答案

您可以不是一个滚轮连接到网页视图但您可以使用手势来这样做。

You cannot attach a scroller to a webview however you can make use of the gesture to do the same.

的手势检测使用这种方法的抛

The gesture detects the fling using this method

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

给的velocityX,velocityY到scoller方法与其他参数一起

Give the velocityX, velocityY to the scoller method along with other parameters

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

扫描computeScrollOffset()值来查找getCurrX(),getCurrY()位置。

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

扩展web视图和覆盖的方法onTouchEvent(MotionEvent EV),dispatchTouchEvent(MotionEvent EV),使得默认触摸事件不是由web视图本身消耗返回false。
现在实施gestureListener并覆盖上述onfling方法。
通过速度等参数的滚动条。
开始一个循环以扫描computeScrollOffset()值来寻找getCurrX()和getCurrY()和每次无效图。
根据需要,通过这个值来滚动网页视图。

Extend the webview and override the methods onTouchEvent(MotionEvent ev), dispatchTouchEvent(MotionEvent ev) to return false so that by default the touch events are not consumed by the webview itself.Now implement the gestureListener and override the onfling method mentioned above.pass the velocity and other parameters to the scroller.Start a loop to scan the computeScrollOffset() value to find the getCurrX() and getCurrY() and invalidate the view each time.Pass this value to scroll the webview as needed.

请让我知道如果你需要什么。

Please let me know in case you need anything.

这篇关于在网页视图平滑水平滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-26 16:12