+ Android的web视图 - 如何自动滚动页面? [英] +Android Webview - how to autoscroll a page?

查看:530
本文介绍了+ Android的web视图 - 如何自动滚动页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在web视图中打开HTML页面并使其按照间隔通过定时器设置自动向下滚动自动。

I'd like to open a html-page in a webview and make it auto-scroll downwards automatically in accordance with an interval set through a timer.

虽然下面的例子是桌面,这个环节应该给你一个想法是什么我想实现(使在页面的右上部分自动滚动):

Although below example is for desktop, this link should give you an idea what I want to achieve (enable autoscrolling in the upper right part of the page):

例如

首先,我想过开一个网页,然后使用某种code这将模拟/触发DPAD向下(或箭头向下)。在Windows Mobile的,我相信有一些所谓的SendKeys,但我找不到在Android的SDK类似的东西(除了测试-SDK,我怀疑我可以使用发布我的Andr​​oidMarket的应用程序),所以我想提到的方法以上是不可能的。

First I thought about opening a webpage and then use some kind of code which would simulate/trigger DPAD-down (or Arrow-down). In Windows Mobile, I believe there was something called SendKeys but I couldn't find something similar in the Android-SDK (except for a test-SDK which I doubt I could use for publishing my app in AndroidMarket) so I guess the way mentioned above is not possible.

另一种解决办法或许是一个java脚本,但网页不是由我创造,所以我不能插入任何锚。

Another solution could perhaps be a java-script but the webpages are not created by me so I can't insert any anchor.

不过,我注意到,web视图有一些方法被称为下页(和PageUp键),它也可能是一个解决方案,但恐怕下页将太多的滚动我想要的方式。我想滚动很慢流畅,更像是一条线的时间。

However, I noted that Webview has some methods called PageDown (and PageUp) which could also be a solution but I am afraid a PageDown would be too much for scrolling the way I want. I want the scrolling to be slow and smooth, more like a line at a time.

你有任何想法如何,我可以实现这个?我真的AP preciate你的帮助。

Do you have any ideas how I could implement this? I'd really appreciate your help.

推荐答案

您可以尝试使用, View.scrollBy(INT X,int y)对滚动的WebView

用途:
  computeVerticalScrollOffset()
computeVerticalScrollExtent()
computeVerticalScrollRange()来计算最大的y值。

You could try using, View.scrollBy(int x, int y) to scroll the WebView.

Use:
computeVerticalScrollOffset(),
computeVerticalScrollExtent()
computeVerticalScrollRange() to calculate a maximum y value.

这篇关于+ Android的web视图 - 如何自动滚动页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆