scrolling a page in WebView programatically

moster67

Expert
Licensed User
Longtime User
Is it possible to scroll a page in WebView programatically, perhaps by using KEYCODE_DPAD_DOWN and KEYCODE_DPAD_UP? If yes, what if the device does not have a DPAD? Will it work anyway?

The idea is to open a webpage and with the help of a timer scroll the page downwards according to a pre-set interval.

Any other way this could be done?
 

moster67

Expert
Licensed User
Longtime User
It seems like SendKeys are not available for Android (except for in a test-SDK) so I guess I can give up the idea of simulating keypresses to scroll down a page in a WebView.

However, I noted that Webview has some methods called PageDown/PageUp (although not implemented in the current WebView-library) 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.

What about Scrollview? Can it be scrolled programatically? If yes, maybe I can add a panel which embeddes a WebView? Is this possible?
 
Upvote 0

moster67

Expert
Licensed User
Longtime User
Thanks. I will try it.


ScrollView can be scrolled programatically. Usually scrollable views like WebView and EditText should not be added to a ScrollView. However it may work in your case.
 
Upvote 0

NeoTechni

Well-Known Member
Licensed User
Longtime User
Could you add support for those scrolling method native to the webview, and a way to detect when the use scrolls outside the boundaries of the page?
wed also need to be able to get the height of the page to scroll a percent
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
Hi.

Take a look at this post on stackoverflow.com.

There's a javascript code example that you could use to scroll a (known) HTML element into view.

If that's not what you need then you could probably use the same javascript method to scroll the page by a number of pixels instead.

Martin.
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
Hi again.

Look at the attached project.

I've used the Reflection library to execute the WebView flingScroll() method.

I can find no detailed documentation for the flingScroll method so am not sure what the two parameters passed to it specify.
I'd have guessed pixels x and y to scroll by but run the attached project and it doesn't look like the WebView is scrolling 500 pixels in y direction to me.

Martin.
 

Attachments

  • FlingScroll.zip
    6.1 KB · Views: 606
Upvote 0
Top