+Android Webview - how to autoscroll a page?

2019-02-19 06:50发布

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):

example

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.

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

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.

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

1条回答
爱情/是我丢掉的垃圾
2楼-- · 2019-02-19 07:26

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

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

查看更多
登录 后发表回答