如何检测webView中的页面顶部?

时间:2016-06-08 10:16:57

标签: android webview

我有WebView。每当我一直向上滚动页面时,我想检测到我在页面顶部的时间。我该怎么做?

我已经延长了

implements OnScrollListener

并自动添加这两个

@Override
public void onScroll(AbsListView arg0, int arg1, int arg2, int arg3) {
    // TODO Auto-generated method stub

}

@Override
public void onScrollStateChanged(AbsListView arg0, int arg1) {
    // TODO Auto-generated method stub

}

然而,我无法添加

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

     if(view.getTop()==t){
        // reaches the top end
        }

    View view = (View) getChildAt(getChildCount()-1); 
    int diff = (view.getBottom()-(getHeight()+getScrollY()+view.getTop()));// Calculate the scrolldiff 
     if( diff <= 0 ){ 
        // if diff is zero, then the bottom has been reached
         Log.d(ScrollTest.LOG_TAG, "MyScrollView: Bottom has been reached" );
             }
    super.onScrollChanged(l, t, oldl, oldt); 
}

它给我的错误是&#34; MainActivity类型的onScrollChanged(int,int,int,int)方法必须覆盖或实现超类型方法&#34;

1 个答案:

答案 0 :(得分:0)

这是因为onScrollChanged不必被覆盖 - 您正在使用@Override。查看文档证实了这一点:只有两种方法属于OnScrollListener接口。 https://developer.android.com/reference/android/widget/AbsListView.OnScrollListener.html

删除@Override,它将解决问题。