小编out*_*ory的帖子

使用带有StaggeredGridLayoutManager的RecyclerView时,如何避免项目之间的双重空间?

我正在使用带有StaggeredGridLayoutManager的RecyclerView来创建一个两列列表.但是如何在左列和右列之间设置右边距.我已经使用此代码从顶部创建右边距,但如何解决列之间的双倍空格.

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;

        // Add top margin only for the first or second item to avoid double space between items
        // Add top margin only for the first or second item to avoid double space between items
        if((parent.getChildCount() > 0 && parent.getChildPosition(view) == 0) …
Run Code Online (Sandbox Code Playgroud)

android margins staggeredgridlayout android-recyclerview

14
推荐指数
4
解决办法
7821
查看次数