webview 中的平滑水平滚动
我有一个包含许多“页面”(文本列)的 wevbiew,并且希望能够在列之间水平滚动以响应 Fling 手势。我可以使用scrollTo() 很好地做到这一点,但这相当突然,我真的希望能够从一个“页面”平滑过渡到下一个“页面”。
我所看到的问题是:您不能将 Scroller 附加到 WebView,也不应该将 WebView 嵌套在 ScrollView 中。
有谁有在 WebView 中实现平滑或动画水平滚动的好主意吗?
编辑添加:我正在尝试实现一个knotmanish的想法,其中我使用独立的滚动器来计算距离..
// 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()方法一样(视图跳转到滚动的末尾)。
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.
The problem as I see it: you can't attach a Scroller to a WebView, and shouldn't nest 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 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();
}
... 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).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您无法将滚动条附加到 Web 视图,但是您可以使用手势来执行相同的操作。
手势使用此方法检测 fling
将velocityX、velocityY 提供给 scoller 方法以及其他参数,
扫描computeScrollOffset() 值以查找getCurrX()、getCurrY() 位置。
扩展 webview 并重写 onTouchEvent(MotionEvent ev)、dispatchTouchEvent(MotionEvent ev) 方法以返回 false,以便默认情况下 webview 本身不会消耗触摸事件。
现在实现gestureListener并重写上面提到的onfling方法。
将速度和其他参数传递给滚动条。
启动一个循环来扫描computeScrollOffset()值以找到getCurrX()和getCurrY()并每次使视图无效。
传递此值以根据需要滚动 Web 视图。
如果您需要任何东西,请告诉我。
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
Give the velocityX, velocityY to the scoller method along with other parameters
scan the computeScrollOffset() value to find the getCurrX(),getCurrY() positions.
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.