问题描述
我的是我的本机应用程序,如果用户滚动到Webview的末尾,我想在其中显示/隐藏一个按钮.我在这里并获得了如何通过接口注册回调的完整思路.我的主要问题是我无法在onScrollChanged方法中获取我的计算结果.我已经尝试过将诸如getHeight(),getContentHeight(),top之类的东西组合在一起,但是似乎触发得太早了.我尝试了一个简单的页面,例如Google的页面,但内容相对较少,还有一个新闻页面.
Mine is a native app where I want to show/ hide a button if the user scrolls to the end of webview. I looked at an answer here and got the entire idea of how to register the callback via interface. My major issue is that I am not able to get my calculations right inside the onScrollChanged method. I have tried combination of things like getHeight(), getContentHeight(), top etc but it just seems to fire too early. I tried with a simple page like google's with comparatively lesser content as well as a news page.
对于正常的滚动视图,这些逻辑可以正常工作.由于网页内容很多,可能会使计算混乱.粘贴示例代码:不起作用.
These logics work fine for a normal scroll view. Since the webpage has a lot of content, it could be messing up the calculations. Pasting a sample code: does not work.
@Override
protected void onScrollChanged(int left, int top, int oldLeft, int oldTop) {
if ( mOnWebViewBottomReachedListener != null ) {
//if ( (getContentHeight() - (top + getHeight())) <= mMinDistance )
int diff = (getBottom() - (getHeight() + getScrollY()));
Log.e("values ", diff+" o");
if ((int) Math.floor(getContentHeight() * getScaleY()) == top)
mOnWebViewBottomReachedListener.onBottomReached(this);
}
super.onScrollChanged(left, top, oldLeft, oldTop);
}
需要帮助.谢谢.
推荐答案
@Override
protected void onScrollChanged(int l, int t, int oldl, int oldt) {
int height = (int) Math.floor(this.getContentHeight() * this.getScale());
int webViewHeight = this.getMeasuredHeight();
if(this.getScrollY() + webViewHeight >= height){
Log.i("THE END", "reached");
}
super.onScrollChanged(l, t, oldl, oldt);
}
此逻辑适用于Web视图.
This logic works fine for a webview.
这篇关于如何在Android中检测WebView的Scrollend?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!