RecyclerView实现瀑布流

1. item乱跳问题

layoutManager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
//item到处跳动,甚至左右两列切换,解决办法
layoutManager.setGapStrategy(StaggeredGridLayoutManager.GAP_HANDLING_NONE);

2.滑动空白的问题

设置了StaggeredGridLayoutManager不处理空白之后,发现反复滑动列表时,顶部item上边会出现空白。网络很多都是讲 监听onScrollListener,然后调用

mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
    @Override
    public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
        super.onScrollStateChanged(recyclerView, newState);
        layoutManager.invalidateSpanAssignments();
    }
});

3.上拉加载刷新

mAdapter.notifyItemChanged(mAdapter.getItemCount());

4 .Adapter解决item位置

@Override
public long getItemId(int position) {
    return position;
}

你可能感兴趣的:(android)