Cur*_*der 4 android scroll android-webview
我有一个要求,我在其下面显示一个带有复选框的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);
}
Run Code Online (Sandbox Code Playgroud)
问题是条件
(getContentHeight() - (top + getHeight()))<= mMinDistance)// mMinDistance在我的情况下为0
甚至在我向下滚动到页面底部之前就满意了.如您所见,我尝试在日志中打印每个值,并发现参数"top"有时会超过值"getContentHeight".
示例日志值:
08-14 11:28:19.401:I/MYACT(1075):内容高度:3020上:3861高度:416分距:0
在这种情况下,我如何避免这种情况?我应该使用不同的方式来检查我是否已向下滚动到页面底部?
谢谢
经过一些研究,我发现了这个问题.Webview通常根据屏幕大小缩放网页,然后呈现它.它通常会缩放页面,使其在手机中看起来不会太小.您可以使用getScale()方法获得此比例因子
因此,在我的情况下,我将使用以下条件来检查是否已到达页面末尾
(getContentHeight()*getScale() - (top + getHeight()))<= mMinDistance)// mMinDistance在我的情况下为0
| 归档时间: |
|
| 查看次数: |
3326 次 |
| 最近记录: |