首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >不带ItemDecoration的StaggeredGridLayoutManager

不带ItemDecoration的StaggeredGridLayoutManager
EN

Stack Overflow用户
提问于 2015-08-24 21:48:03
回答 1查看 1.1K关注 0票数 1

没有ItemDecoration的StaggeredGridLayoutManager需要onScroll以矩阵/网格格式排列项目。有没有一种方法可以避免ItemDecoration,因为我不想在项目之间使用装饰器。

代码语言:javascript
复制
recyclerView.setLayoutManager(new StaggeredGridLayoutManager(3,StaggeredGridLayoutManager.VERTICAL)) 
//Without addItemDecoration - it requires a scroll to occupy all the columns
recycler.addItemDecoration(new CustomInsetsDecoration(context));

没有物品装饰--

代码语言:javascript
复制
A
B
C
D
E
F

带项目装饰(最小1px/dp分开)

代码语言:javascript
复制
A B C
D E F

我想要的:

代码语言:javascript
复制
ABC
DEF

A,B,C,D,E,F都是ImageViews (大小不同)

我的项目布局-一个非常简单的-相对布局和一个图像视图:

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <ImageView
        android:id="@+id/item_browse_cover"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:scaleType="centerCrop" />

</RelativeLayout>

任何意见都是值得感谢的。提前谢谢。

EN

回答 1

Stack Overflow用户

发布于 2015-08-24 22:49:12

使用下面的MarginDecorator类,边距为0

代码语言:javascript
复制
public class MarginDecorator extends RecyclerView.ItemDecoration {

    private int margin;

    public MarginDecorator(int margin) {
        this.margin = margin;
    }

    @Override
    public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
        outRect.top = margin;
        outRect.bottom = margin;
        outRect.left = margin;
        outRect.right = margin;
    }
}

也可以尝试使用setGapStrategy()

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32183973

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档