我创建了一个包含Webview的简单应用,并在其中展示了Web内容。
我的问题是,是否有可能限制滚动边界,以至于我们不能落后于某些边界,例如,如果这是整个页面,并且高度为100 000 px,我想“跳过”或“切除”例如前1000 px,并且当用户上下滚动时,设置限制,而不是让它们越过某个限制,在我的情况下,限制位于顶部,我不希望以显示页面的第一部分。
this is how it loads now and this is how it should be loaded
and "locked"
-------------------------------- --------------------------------
| | | ___ |
| | | ___ this is hamburger menu |
| part to skip over | | ___ |
| | | |
|this line represents boundary | | |
|I do not want to cross when | | |
| users scrolls up | | |
| --------------------------- | | |
| | | |
| ___ | | |
| ___ this is hamburger menu | | |
| ___ | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
-------------------------------- --------------------------------
. .
. .
. .
rest of web page rest of web page
我尝试过
mWebView.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
//view.scrollTo(0,70); //puts me on good position on webpage, problem, does not create the boundary beyond which it can not be passed
//view.setScrollY(70); //puts me on good position on webpage, problem, does not create the boundary beyond which it can not be passed
//view.setTop(-70); //setPadding this is good in because it create limits on the top, but it cut off hamburger menu bar
//view.setY(-70); //setPadding this is good in because it create limits on the top, but it cut off hamburger menu bar
//view.scrollBy(0,999); //this just goes to certain height but dont put boundaries to the top which it cannot be passed
我甚至在此link上发现了一个有趣的主意,因为我试图覆盖WebView link2的行为,但是在我的CustomWebView中,我做到了
protected int computeVerticalScrollRange(WebView view) {
int heighy1 = view.getHeight() - 1000;
return super.computeVerticalScrollRange() - heighy1;
}
当我在public void onPageFinished(WebView视图,字符串url)中调用
mWebView.computeVerticalScrollRange(view);
什么也没发生,也许我做错了。
我在任何地方都找不到解决问题的方法。
提前谢谢!
我感谢任何帮助。