Android 自定义 LayoutManager 实现头重式效果

前言

爱奇艺阅读效果

    之前学习了自定义RecyclerView的LayoutManager,一直无用武之地,最近看“爱奇艺阅读”时发现了个不错的RecyclerView LayoutManger样式,于是自己来实现一波,正好巩固下。

实现功能:

  • 头重式UI
  • 滑动item变化流畅
  • 子视图回收复用
  • 支持按页滑动,头页与左边界对齐
  • 可限制滑动后filling的页数
  • 支持无限轮播
  • 自定义子视图缩放大小及间距

效果图




使用说明

Dependency:

Step 1. Add the JitPack repository to your build file

allprojects {
        repositories {
            ...
            maven { url 'https://jitpack.io' }
        }
    }

Step 2. Add the dependency

dependencies {
            implementation 'com.github.ljm17:TopHeavyLayoutManager:1.1.0'
    }

Explain:

构造方法:

//TopHeavyLayoutManager
TopHeavyLayoutManager();
TopHeavyLayoutManager(int space);
TopHeavyLayoutManager(float childScale, float coverScale);
TopHeavyLayoutManager(int space, float childScale, float coverScale);

//TopSnapHelper
TopSnapHelper(int fillingLimit);
参数介绍
space相邻child view之间的间距,默认 60 px
childScale尾部child view的缩放值,默认 0.5f
coverScale头部被覆盖的child view的缩放值,默认0.8f
fillingLimit手指离开后filling的页数限制

如果想要实现无限循环,只需在RecyclerView.Adapter的getItemCount中返回Integer.MAX_VALUE,设置无限循环后,默认首个展示的item position为Integer.MAX_VALUE/2,若需调整请调用mRecyclerView.scrollToPosition(position)方法

*注意:不宜设置ItemDecoration,以免引起布局偏差。

Example:

mRecyclerView.setLayoutManager(new TopHeavyLayoutManager());
mRecyclerView.setAdapter(new xxxAdapter());
TopSnapHelper helper = new TopSnapHelper(2);
helper.attachToRecyclerView(mRecyclerView);

项目地址

    https://github.com/ljm17/TopHeavyLayoutManager
    如有问题欢迎指出,若对你有帮助给个star把~

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值