【问题标题】:How to detect how much the view has scroll ScrollView如何检测视图有多少滚动 ScrollView
【发布时间】:2012-09-14 15:23:52
【问题描述】:

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

【问题讨论】:

    标签: android scrollview android-scrollview


    【解决方案1】:

    你需要重写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);
    }
    

    这里,diff 是在ScrollView 的底部边缘和底部当前可见的内容之间留出的滚动空间。当diff = 0 时,ScrollView 已完全向下滚动。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-11
      相关资源
      最近更新 更多