尝试检测,如果滚动网页视图上下时,奇怪的失算 [英] Weird miscalculation when trying to detect if WebView scrolled to bottom

查看:114
本文介绍了尝试检测,如果滚动网页视图上下时,奇怪的失算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,当的WebView 滚动到下探测。我用下面的code:

I have a problem detecting when WebView is scrolled to bottom. I use following code:

@Override
protected void onScrollChanged(int x, int y, int oldX, int oldY) {
    super.onScrollChanged(x, y, oldX, oldY);

    int bottom = ((int) Math.floor(getContentHeight() * getScale()) - getHeight());
    MyLogger.log(y + "____" + bottom);

    if (y == bottom) {
        // Trigger listener
    }
}

日志给我下面的输出:

Logging gives me following output:

162____164

所以,在某种程度上有2像素误判这里,我不知道在哪里,就是从。

So somehow there is 2 pixel miscalculation here and I have no idea where is that coming from.

感谢。

推荐答案

你在那里似乎是正确的计算。这将是pssed更好的前$ P $:

The calculation you have in there seems correct. It would be better expressed as:

@Override
protected void onScrollChanged(int x, int y, int oldX, int oldY) {
    super.onScrollChanged(x, y, oldX, oldY);
    final int DIRECTION_UP = 1;
    if (!canScrollVertically(DIRECTION_UP)) {
        // Trigger listener.
    }
}

有一对夫妇的情况下,你可能无法检测到你在页面的底部这样的:

There are a couple of cases where you might not be able to detect that you're at the bottom of the page this way:


  • 如果在页面处理采用触摸处理程序和pageScale()滚动大于1.0。在这种情况下,'底'在CSS中检测坐标空间中,由于四舍五入的原因,可能不总是正确映射到android.view.View坐标空间(虽然这应固定在奇巧)。

  • 您或您所使用的覆盖 WebView.scrollTo / overScrollBy /等不某些库允许滚动一路走到底。
  • If the page is handling the scrolling using touch handlers and the pageScale() is greater than 1.0. In this case 'bottom' is detected in the CSS coordinate space and, due to rounding, may not always map correctly to the android.view.View coordinate space (although this should be fixed in KitKat).
  • You or some library you're using is overriding WebView.scrollTo/overScrollBy/etc.. to not allow the scroll to go all the way to the bottom.

作为最后的手段变通方法,您可以覆盖<一个href=\"http://developer.android.com/reference/android/webkit/WebView.html#onOverScrolled%28int,%20int,%20boolean,%20boolean%29\"相对=nofollow> onOverScrolled :

As a last resort workaround you could override onOverScrolled:

@Override
protected void onOverScrolled (int scrollX, int scrollY, boolean clampedX, boolean clampedY) {
    if (scrollY > 0 && clampedY && !startedOverScrollingY) {
        startedOverScrollingY = true;
        // Trigger listener.
    }
    super.onOverScrolled(scrollX, scrollY, clampedX, clampedY);
}

@Override
protected void onScrollChanged(int x, int y, int oldX, int oldY) {
    super.onScrollChanged(x, y, oldX, oldY);
    if (y < oldY) startedOverScrollingY = false;
}

如果该再现上最新的Andr​​oid版本中,你能不能发送错误报告。理想的情况下创建一个简约的应用程序,一个空白的(或简单)网页转载了问题。

If this reproduces on the newest Android release, could you file a bug report. Ideally create a minimalistic application that reproduces the issue with a blank (or trivial) page.

这篇关于尝试检测,如果滚动网页视图上下时,奇怪的失算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆