如何实现 Staggered GridView with Sections?

How to implement Staggered GridView with Sections?

我只想在 Staggered GridView 中实现 部分 例如今天、昨天和其他。 我试过下面的库,但我没有运气。

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

你能就如何实现这个提出任何建议吗?

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

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

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

这是 link 我为此创建了一个演示 StaggeredGridViewSections

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

您可以将 StaggeredGridLayoutManager 与一个适配器一起使用并设置两个 ItemViewType 并将剖面视图的全跨度设置为 true。

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