【发布时间】:2015-09-21 14:15:08
【问题描述】:
我在单个 Scrollview 中有 2 个水平和 1 个垂直(网格布局)。
<ScrollView>
<Horizontal RecyclerView/>
<Horizontal RecyclerView/>
<Vertical RecyclerView/>
</ScrollView>
以上是我的观点示意图。
一旦垂直 recyclerviews 最后一项可见,我必须加载数据,但我无法获取垂直视图的滚动事件。
这是我的滚动视图监听器。
recyclerView.setOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
totalItemCount = gridLayoutManager.getItemCount();
lastVisibleItem = gridLayoutManager.findLastVisibleItemPosition();
if (!loading && totalItemCount <= (lastVisibleItem + visibleThreshold)) {
// End has been reached
// Do something
if(onLoadMoreListener!=null) {
onLoadMoreListener.onLoadMore(lastVisibleItem);
}
loading = true;
}
}
});
但是这个 setonscrollListener 永远不会被触发。如何获得上述情况的滚动事件。
提前致谢:)
【问题讨论】:
-
我不认为嵌套的可滚动视图是最好的主意(就像 ScrollView 中的 RecyclerView),虽然现在从 API 21 开始支持它。但无论如何,看看这个,它可以帮忙:stackoverflow.com/questions/6210895/…
-
在彼此内部使用两个可滚动的 View 有点困难,当你希望它们灵活时变得更加困难。
标签: android scrollview android-recyclerview