scrollView.getScrollY()始终返回0

时间:2015-08-10 02:38:06

标签: android android-scrollview

我想知道我的ScrollView何时滚动到顶部。 这就是我试过的:

  scrollView.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {

            @Override
            public void onScrollChanged() {
                int scrollX = scrollView.getScrollX(); //for horizontalScrollView
                int scrollY = scrollView.getScrollY();
                Log.d("TagFragment", "scrollY" + scrollY);
                mainFragment.setCanPullToRefresh(scrollY == 0);
            }
        });

问题是:scrollY几乎总是0.所以它几乎总是返回true。有些值是正确的:

logcat的:

D/TagFragment﹕ scrollY242
D/TagFragment﹕ scrollY0
D/TagFragment﹕ scrollY0
D/TagFragment﹕ scrollY0
D/TagFragment﹕ scrollY0
D/TagFragment﹕ scrollY0
D/TagFragment﹕ scrollY244
D/TagFragment﹕ scrollY0
D/TagFragment﹕ scrollY0
D/TagFragment﹕ scrollY0
D/TagFragment﹕ scrollY0
D/TagFragment﹕ scrollY0
D/TagFragment﹕ scrollY245
D/TagFragment﹕ scrollY0
D/TagFragment﹕ scrollY0
D/TagFragment﹕ scrollY0
D/TagFragment﹕ scrollY0
D/TagFragment﹕ scrollY0
D/TagFragment﹕ scrollY246
D/TagFragment﹕ scrollY0

我怎么能100%准确地知道偏移是什么?

0 个答案:

没有答案