具有全宽标题的RecyclerView GridLayoutManager [英] RecyclerView GridLayoutManager with full width header

查看:153
本文介绍了具有全宽标题的RecyclerView GridLayoutManager的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个非常有用的示例此处显示一个RecyclerView和一个GridLayoutManager来显示带有标题的网格.

I'm using a very helpful example here to show a RecyclerView and a GridLayoutManager to show a grid with a header.

看起来不错,但是我的图形设计师希望标题项目占用RecyclerView的整个宽度.现在有填充.

It looks pretty good, but my graphic designer wants the header item to take up the full width of the RecyclerView. Right now there is padding.

当我设置GridLayoutManager时,我添加了填充(对于其他网格项目,我仍然想要填充):[它正在使用Xamarin C#]

When I set up the GridLayoutManager I add in padding (which I still want for the other grid items): [it's using Xamarin C#]

var numColumns = myListView.MeasuredWidth / tileSizeMax;
myGridView.SetPadding(tilePadding, tilePadding, tilePadding, tilePadding);
layoutManager = new GridLayoutManager(Activity, numColumns);
myListView.SetLayoutManager(layoutManager);

那么,如何设置标题项的填充不同...或使其自身在填充上绘制呢?

So, how can I set the padding to be different for the header item...or make it draw itself over the padding?

推荐答案

尝试一下:

mLayoutManager = new GridLayoutManager(this, 2);
        mLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
            @Override
            public int getSpanSize(int position) {
                switch(mAdapter.getItemViewType(position)){
                    case MyAdapter.HEADER:
                        return 2;

                    case MyAdapter.ITEM:
                    default:
                        return 1;
                }
            }
        });

并检查以下链接:

http://blog.sqisland.com/2014/12/recyclerview-grid-with-header.html 使用SpanSizeLookup在GridLayoutManager中设置项目的跨度

这篇关于具有全宽标题的RecyclerView GridLayoutManager的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆