142

支持粘性Item的RecyclerView布局管理器

 6 years ago
source link: https://juejin.im/post/5a25f82d51882531ea651f31
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

支持粘性Item的RecyclerView布局管理器

2017年12月05日 02:18 ·  阅读 3110

很多 App 都被设计了分组列表有粘性条目的效果,而现在我们开发安卓,基本都用上了RecyclerView,这里介绍的这个开源项目就是在RecyclerView上实现了这个效果,让我们看下效果图:

Image Image Image
1602451814aa9688~tplv-t2oaga2asx-zoom-in-crop-mark:3024:0:0:0.awebp 1602451817685cbc~tplv-t2oaga2asx-zoom-in-crop-mark:3024:0:0:0.awebp 1602451814f66b95~tplv-t2oaga2asx-zoom-in-crop-mark:3024:0:0:0.awebp

StickyLayoutManager完全开源 Github

首先Adapter需要实现StickyHeaders接口并实现方法

class RecyclerView.Adapter implements StickyHeaders {
  public boolean isStickyHeader(int position) {
    // Implement this method
  }
}
复制代码

然后设置相应的布局管理器

RecyclerView.setLayoutManager(new StickyHeaders...xxx...LayoutManager<RecyclerView.Adapter & StickyHeaders>());
复制代码

默认实现了StickyHeadersLinearLayoutManagerStickyHeadersGridLayoutManagerStickyHeadersStaggeredGridLayoutManager.

本开源库并非由我开发,我只是基于作者Doist开发的这个开源项目整理而来,作者只实现了StickyHeadersLinearLayoutManager


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK