我找到了这个代码并将其改编为我的项目

@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
    super.onScrolled(recyclerView, dx, dy);
    visibleItemCount = mLayoutManager.getChildCount();
    //totalItemCount = mLayoutManager.getItemCount();

    int[] firstVisibleItems = null;
    firstVisibleItems = mLayoutManager
            .findFirstVisibleItemPositions(firstVisibleItems);
    if (firstVisibleItems != null && firstVisibleItems.length > 0) {
        pastVisibleItems = firstVisibleItems[0];
    }

    if (!loading && visibleItemCount <= (pastVisibleItems + visibleThreshold)) {
        // End has been reached
        // Do something

        Log.d(TAG, "onLoadMoreListener ");

        getTagResults(mQuery, mMinId, mMaxId);

        // if (onLoadMoreListener != null) {
        //      onLoadMoreListener.onLoadMore();
        //  }


        loading = true;
    }

}

但这不起作用,它的线性布局虽然工作。我已经找到了很多其他布局的代码,但是我找不到如何在到达终点时加载更多的结果。

最佳答案

使用以下代码

RecyclerView.LayoutManager layoutManager;
layoutManager = new GridLayoutManager(getActivity(), 2);
recyclerView.setLayoutManager(layoutManager);

关于android - 网格布局与回收者 View android,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35664260/

10-08 23:33