【问题标题】:How to implement Staggered GridView with Sections?如何使用 Sections 实现交错的 GridView?
【发布时间】:2015-04-17 08:39:46
【问题描述】:

我只想在Staggered GridView.中实现sections,例如今天、昨天和其他。 我尝试过使用以下库,但我没有运气。

  1. Staggered GridView
  2. 带有 StaggeredGridLayoutManager 的 RecyclerView。

您能否就如何实现这一点提出任何建议?

【问题讨论】:

标签: android gridview android-recyclerview staggered-gridview


【解决方案1】:

您可以将 StaggeredGridLayoutManager 与自定义 ItemDecoration 一起使用。

这是一个使用 LinearLayoutManager 的库, sticky-headers-recyclerview。您也许可以根据自己的需要对其进行调整,或者至少知道如何去做。

【讨论】:

    【解决方案2】:

    我已经通过在 SimpleAdapter.java 中使用 RecyclerView 和 StaggeredGridLayoutManger 来实现这一点。

          if (position % 5 == 0) {
                StaggeredGridLayoutManager.LayoutParams layoutParams = (StaggeredGridLayoutManager.LayoutParams) holder.itemView.getLayoutParams();
                layoutParams.setFullSpan(true);
            } else {
                StaggeredGridLayoutManager.LayoutParams layoutParams = (StaggeredGridLayoutManager.LayoutParams) holder.itemView.getLayoutParams();
                layoutParams.setFullSpan(false);
            }
    

    这是我为此创建的演示的链接 StaggeredGridViewSections

    【讨论】:

      【解决方案3】:

      如果您不需要 RecycleView,那是另一种选择:https://github.com/sarahlensing/StaggeredGridView

      【讨论】:

        【解决方案4】:

        您可以将 StaggeredGridLayoutManager 与一个适配器一起使用并设置两个 ItemViewTypes 并且对于剖面视图,将 full span 设置为 true。

        StaggeredGridLayoutManager.LayoutParams layoutParams = (StaggeredGridLayoutManager.LayoutParams) holder.itemView.getLayoutParams();
                layoutParams.setFullSpan(true);
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2020-06-20
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2017-08-10
          • 1970-01-01
          相关资源
          最近更新 更多