简体   繁体   English

如何检测视图有多少滚动ScrollView

[英]How to detect how much the view has scroll ScrollView

如何检测滚动视图滚动了多少?

You need to override the onScrollChanged() method of the ScrollView: 您需要重写ScrollView的onScrollChanged()方法:

@Override
protected void onScrollChanged(int l, int t, int oldl, int oldt) {

    Log.i(TAG, "View onScrollChanged");
    View view = (View) getChildAt(getChildCount() - 1);
    int diff = (view.getBottom() - (getHeight() + getScrollY()));// Calculate

    super.onScrollChanged(l, t, oldl, oldt);
}

Here, diff is the space left for scrolling between the bottom edge of the ScrollView , and the currently visible content at the bottom. 在这里, diffScrollView底部边缘与底部当前可见内容之间滚动的剩余空间。 When diff = 0 , the ScrollView has been scrolled down fully. diff = 0ScrollView已完全向下滚动。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM