Dav*_*vid 28 android onscrolllistener android-recyclerview
我正在使用RecyclerView,ScrollListener:
mRecyclerView.setOnScrollListener(new RecyclerView.OnScrollListener()
{
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState)
{
super.onScrollStateChanged(recyclerView, newState);
}
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy)
{
super.onScrolled(recyclerView, dx, dy);
// Do my logic
}
});
Run Code Online (Sandbox Code Playgroud)
当我用手指滚动时,滚动侦听器触发了罚款.
但是当我逐步滚动时,就像那样:
mRecyclerView.scrollToPosition(LAST_POSITION);
Run Code Online (Sandbox Code Playgroud)
滚动侦听器未被触发.
小智 26
我遇到了同样的问题并找到了一种解决方法,即在布局管理器中使用smoothScrollToPosition.此方法触发滚动侦听器.所以基本上这就是我用来拥有的东西:
recyclerView.scrollToPosition(recyclerAdapter.getItemCount() - 1);
Run Code Online (Sandbox Code Playgroud)
现在我改为:
recyclerView.getLayoutManager().smoothScrollToPosition(recyclerView, null, recyclerAdapter.getItemCount() - 1);
Run Code Online (Sandbox Code Playgroud)
它对我来说很好.
yig*_*git 24
这是一个已知的问题.这是因为RecyclerView不知道LayoutManager如何处理滚动或者它是否会处理滚动.
在下一个版本中,您将收到一个调用,onScrolled如果布局后第一个和最后一个子位置发生更改(通常是调用滚动到位置的结果).
不幸的是,dx和dy将为0,因为RecyclerView并不真正知道布局管理器滚动处理scrollTo请求的程度.或者,您也可以使用ViewTreeObserver的滚动回调.
| 归档时间: |
|
| 查看次数: |
20465 次 |
| 最近记录: |