小编Seb*_*ian的帖子

Android RecyclerView StaggeredGrid项在滚动顶部时更改位置

在我的2列交错网格中,我使用无限列表的效果自动按10乘10加载元素,除了向上滚动时,其他所有东西都工作正常。前两个元素更改其位置。就像前两个项目从一列跳到另一列一样。

如我所读,适配器必须保存每个元素的状态。但是,我不知道该怎么做。

这是我用来显示StaggeredGrid功能的主要代码

public class SpacesItemDecoration extends RecyclerView.ItemDecoration {
    private int space;

    public SpacesItemDecoration(int space) {
        this.space = space;
    }

    @Override
    public void getItemOffsets(Rect outRect, View view,
                               RecyclerView parent, RecyclerView.State state) {
        outRect.left = space;
        outRect.right = space;
        outRect.bottom = space+1;

        // Add top margin only for the first item to avoid double space between items
        if(parent.getChildLayoutPosition(view) == 0)
            outRect.top = space;
    }
}

public class SolventViewHolders extends RecyclerView.ViewHolder implements View.OnClickListener {

    public TextView vh_name;
    public TextView vh_price;
    public ImageView …
Run Code Online (Sandbox Code Playgroud)

android vertical-scrolling staggered-gridview android-recyclerview

3
推荐指数
1
解决办法
4721
查看次数