【问题标题】:RecyclerView GridLayoutManager with full width header带有全宽标题的 RecyclerView GridLayoutManager
【发布时间】:2016-06-05 14:11:42
【问题描述】:

我使用了一个非常有用的示例 here 来显示 RecyclerView 和 GridLayoutManager 来显示带有标题的网格。

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

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

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

那么,我怎样才能将页眉项的填充设置为不同...或者让它自己在填充上绘制?

【问题讨论】:

    标签: android android-recyclerview gridlayoutmanager


    【解决方案1】:

    试试这个:

    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;
                    }
                }
            });
    

    并检查这些链接:

    【讨论】:

    • 你拯救了我的一天! mAdapter.getItemViewType(position) 正是我迫切需要的行!
    • 如何处理最后一项的装饰器?
    • 我想我们永远不会知道
    • @Kenji 作为提示,你可以检查:gitlab.com/snippets/1895752 它有一个视图参考,你有它的位置,所以你可以用你的一些想法来修改它;)
    • 很好的解决方案,救了我的命 :)
    猜你喜欢
    • 2020-02-07
    • 1970-01-01
    • 1970-01-01
    • 2022-01-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多