我有一个要求,我需要在其下方显示一个带有复选框的 WebView。该复选框最初处于禁用状态。只有当用户向下滚动到 webview 的底部时,才会启用该复选框。我通过扩展 Webview 类并编写我的 onScrollChanged 侦听器来做到这一点,如下所示:
@Override
protected void onScrollChanged(int left, int top, int oldLeft, int oldTop) {
if ( (getContentHeight() - (top + getHeight())) <= mMinDistance )
{
Log.i("MYACT","content height: "+getContentHeight()+" top: "+top+" Height: "+getHeight()+" minDistance: "+mMinDistance);
Log.i("MYACT", "Reached bottom");
mOnBottomReachedListener.onBottomReached(this);
}
else{
Log.i("MYACT","content height: "+getContentHeight()+" top: "+top+" Height: "+getHeight()+" minDistance: "+mMinDistance);
Log.i("MYACT", "Not at bottom");
mOnBottomReachedListener.onNotAtBottom(this);
}
super.onScrollChanged(left, top, oldLeft, oldTop);
}
问题是条件
(getContentHeight() - (top + getHeight())) <= mminDistance) //mminDistance 在我的例子中是 0
甚至在我向下滚动到页面底部之前都很满意。如您所见,我尝试在日志中打印每个值,发现参数"top"有时超过值"getContentHeight"。
样本日志值:
08-14 11:28:19.401:I/MYACT(1075):内容高度:3020 顶部:3861 高度:416 分钟距离:0
在这种情况下,我怎样才能避免这种情况?我是否应该使用不同的方式来检查我是否已向下滚动到页面底部?
谢谢