Reputation: 5226
I'm playing with webviews in Android and got stuck on the idea of making animation for scrollTo method. Basically the method scrollTo(x,y) scrolls the page to the given point, but it does it instantly.
I would like it to be slower, like an animation transition. Anyone knows how to do it?
Edit 1: I just tried with xml and code based Translate animations. It seems to move the webview, but only as a "whole" view, so it scrolls down, but not the webview's scrollbar but rather the whole viewport of the webview (does it make sense?) So effectively I can see my current page sliding down with a black screen sliding after it (from top do the bottom). It kind of makes sense, because I'm translating the whole webview (move it down...). I've tried to set Animation.ABSOLUTE, Animation.RELATIVE_TO_PARENT and Animation.RELATIVE_TO_SELF respectively, with no success.
How can I then animate the position of the scroll directly in the webview rather then the whole view?
Edit 2: After several more tries, I understand more how the animations work. I therefore claim that it's not possible to override default "instant" scrollTo behaviour. If anyone has a different opinion or knowledge about that, let me know.
Upvotes: 2
Views: 3038
Reputation: 5541
Use ObjectAnimators. This code smoothly scrolls the WebView to the top:
ObjectAnimator anim = ObjectAnimator.ofInt(mWebView, "scrollY",
mWebView.getScrollPositionY(), 0);
anim.setDuration(400);
anim.start();
Upvotes: 11