我只是想在底部检测滚动nestedscrollview android的位置,以及调用函数.我的代码是:
scroll.getViewTreeObserver()
.addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {
@Override
public void onScrollChanged() {
int totalHeight = scroll.getChildAt(0).getHeight();
int scrollY = scroll.getScrollY();
Log.v("position", "totalHeight=" + totalHeight + "scrollY=" + scrollY);
if (scrollY==totalHeight) {
getPlaylistFromServer("more");
}
}
});
Run Code Online (Sandbox Code Playgroud)
但总高度与MAX ScrollY不同.怎么解决?
我试图在 STATE_IDLE 或 DRAGGING 时检测滚动状态。作为参考,我找到了这个答案:
这帮助我了解了基本的想法,我实现了它,但它只是检测 STATE_IDLE 和强制方法
@Override
public void stopNestedScroll() {
super.stopNestedScroll();
dispatchScrollState(RecyclerView.SCROLL_STATE_IDLE);
}
Run Code Online (Sandbox Code Playgroud)
另外两个方法 onStartNestedScroll 和 startNestedScroll 永远不会被调用,所以由于检查dispatchScrollState中的状态,我永远不会在扩展接口的地方调用我的方法。
我添加的唯一额外的事情是我扩展了我的课程
NestedScrollingView.NestedScrollViewScrollStateListener
Run Code Online (Sandbox Code Playgroud)
并将此类中的scrollListener设置为:
nestedScrollView.setScrollListener(this);
Run Code Online (Sandbox Code Playgroud)
那么是什么原因导致它不调用启动方法呢?