首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >GridLayoutManager定制

GridLayoutManager定制
EN

Stack Overflow用户
提问于 2017-09-27 09:58:15
回答 1查看 3K关注 0票数 2

我想知道是否有办法在android中自定义gridlayoutmanager,使其具有如下所示的水平布局:

我尝试了一些布局管理器,这是我在Github中找到的,但是它们没有帮助我实现这种布局管理器。

就像这样:

代码语言:javascript
复制
public class CustomLayoutManager extends StaggeredGridLayoutManager {
public CustomLayoutManager(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    super(context, attrs, defStyleAttr, defStyleRes);
}

public CustomLayoutManager(int spanCount, int orientation) {
    super(spanCount, orientation);
}

@Override
public void onMeasure(RecyclerView.Recycler recycler, RecyclerView.State state, int widthSpec, int heightSpec) {
    super.onMeasure(recycler, state, widthSpec, heightSpec);
}

@Override
public void setSpanCount(int spanCount) {
    super.setSpanCount(spanCount);
}}

如有任何帮助,将不胜感激。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-09-27 10:49:11

我不认为你需要CustomLayoutManager。这样做对你的RecyclerView

代码语言:javascript
复制
GridLayoutManager layoutManager = new GridLayoutManager(itemView.getContext(), 2, GridLayoutManager.HORIZONTAL, false);
layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
    @Override
    public int getSpanSize(int position) {
        return position == 0 ? 2 : 1;//put your condition here
    }
});
recyclerView.setLayoutManager(layoutManager);
票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46444900

复制
相关文章

相似问题

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