前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >RecyclerView的一些开源LayoutManager

RecyclerView的一些开源LayoutManager

作者头像
用户3106371
发布2018-09-12 10:12:23
3.2K0
发布2018-09-12 10:12:23
举报
文章被收录于专栏:lzj_learn_note

Google默认为RecyclerView提供了LinearLayoutManager、StaggeredGridLayoutManager、GridLayoutManager,已经可以满足很多开发需求了,但是实际开发过程中,免不了出现一些更加新颖的交互设计。下面是收集的一些自定义的LayoutManager。

FanLayoutManager

Github源码地址:[https://github.com/Cleveroad/FanLayoutManager(https://github.com/Cleveroad/FanLayoutManager)

CarouselLayoutManager

Github源码地址:https://github.com/Azoft/CarouselLayoutManager

ChipsLayoutManager

Github源码地址:https://github.com/BelooS/ChipsLayoutManager 一种流式布局的效果,很像我们平时看到的标签云。

HiveLayoutManager

Github源码地址:https://github.com/Chacojack/HiveLayoutManager 一个蜂巢布局管理器

vlayout

Github源码地址:https://github.com/alibaba/vlayout vlayout 是手机天猫 Android 版内广泛使用的一个基础 UI 框架项目,提供了一个用于 RecyclerView 的自定义的 LayoutManger,可以实现不同布局格式的混排,也是 Tangram 框架的基础模块。

flexbox-layout

Github源码地址:https://github.com/google/flexbox-layout flexbox-layout是Google开源的布局,其效果是实现类似CSS中的Flexbox布局效果( 具体可看:https://www.w3cplus.com/css3/a-guide-to-flexbox-new.html ),原本并不支持RecyclerView,但其最新的Alpha版本已经开始推出FlexboxLayoutManager用于支持RecyclerView实现效果。

LondonEyeLayoutManager

Github源码地址:https://github.com/danylovolokh/LondonEyeLayoutManager 一个环形菜单的布局管理器

ZLayoutManager

Github源码地址:https://github.com/mcxtzhang/ZLayoutManager 仿探探、人人影视 卡片层叠 炫动滑动布局

GalleryLayoutManager

Github源码地址:[https://github.com/BCsl/GalleryLayoutManager] 使用自定义 LayoutManager 实现 Android 中 Gallery 或者 ViewPager 控件的效果,支持垂直和水平两个方向,支持 RecycleView 的试图回收机制

CustomLayoutManager

圆弧

缩放

圆弧+缩放

画廊

用法 在build.gradle中添加

compile 'rouchuan.customlayoutmanager:customlayoutmanager:1.0.1'

然后新建layoutManager并继承CustomLayoutManager,CustomLayoutManager有几个默认的属性是可以直接使用的。

代码语言:javascript
复制
protected Context context;
//子view的宽度 
protected int mDecoratedChildWidth;
//子view的高度
protected int mDecoratedChildHeight;
//子view距离屏幕最左的偏移,也可以理解为第一个子view在初始状态下距离屏幕左侧的位移,默认居中
protected int startLeft; 
//子view距离屏幕顶部的位移,默认居中
protected int startTop; 
//主要随滑动所改变的属性的偏移量,考虑到view的属性有int,有float所以这边统一用float表示偏移
protected float offset;  
//相邻两个子view间,主要随滑动而改变的属性的差值(比如随滑动改变的是view的角度,那么这个值就是各个view之间的角度间隔)
protected float interval;

继承CustomLayoutManager之后必须实现3个方法

代码语言:javascript
复制
public class MyLayoutManager extends CustomLayoutManager{

    //默认isClockWise为true
    public MyLayoutManager(Context context) {
        super(context);
    }

    //isClockWise为true时从左往右排列,不然则从右往左排列
    public MyLayoutManager(Context context, boolean isClockWise) {
        super(context, isClockWise);
    }

   //这个方法会设置默认的interval变量,之后可以直接使用interval
    @Override
    protected float setInterval() {
        return 0;
    }

   //初始化方法,你可以在这里初始化自己的一些参数,比如实现圆弧布局的半径,或是更改一些默认的属性,比如startLeft,startTop
    @Override
    protected void setUp() {

    }

   //itemView就是每一个子view,targetOffset就是其对应的将要改变到的属性值,你可以在这里根据targetOffset对子view的一些属性进行设置
    @Override
    protected void setItemViewProperty(View itemView, float targetOffset) {

    }
}

此外还有6个可以选择重写的方法

代码语言:javascript
复制
//当子view的属性超过这个值时,就会被回收掉
@Override
protected float maxRemoveOffset() {
    return getHorizontalSpace() - startLeft;
}

//当子view的属性小于这个值时,就会被回收掉
@Override
protected float minRemoveOffset() {
    return -mDecoratedChildWidth-getPaddingLeft() - startLeft;
}

//当view的属性等于targetOffset时,此view基于初始位置的x坐标,一般返回targetOffset
@Override
protected int calItemLeftPosition(float targetOffset) {
    return targetOffset;
}

//当view的属性等于targetOffset时,此view基于初始位置的y坐标,一般返回0
@Override
protected int calItemTopPosition(float targetOffset) {
    return 0;
}

//这边返回在滚动时子view主要改变的属性的值
@Override
protected float propertyChangeWhenScroll(View itemView) {
    return itemView.getLeft()-startLeft;
}

//滑动产生的偏移dx与offset的比例,默认为1
protected float getDistanceRatio(){
    return 1f;
}
最后

本文部分转至:关于Android RecyclerView的那些开源LayoutManager

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2017.06.26 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • FanLayoutManager
  • CarouselLayoutManager
    • ChipsLayoutManager
      • HiveLayoutManager
      • vlayout
      • flexbox-layout
      • LondonEyeLayoutManager
      • ZLayoutManager
      • GalleryLayoutManager
      • CustomLayoutManager
      • 最后
      领券
      问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档