All Projects → JasonGaoH → Nestedrecyclerview

JasonGaoH / Nestedrecyclerview

🔥Copied the homepage of taobao and jd.com, and realized the TAB ceiling effect through two-layer nesting RecyclerView .

Programming Languages

kotlin
9241 projects

Projects that are alternatives of or similar to Nestedrecyclerview

Dragselectrecyclerview
TouchListener that can be attached to any RecyclerView and handles multi selection for you
Stars: ✭ 371 (-22.55%)
Mutual labels:  recyclerview
Popupbubble
🅿️ Easily add and customise "New Post" popup button with the feeds (RecyclerView) of your app.
Stars: ✭ 385 (-19.62%)
Mutual labels:  recyclerview
Distributed Systems Technologies And Cases Analysis
《分布式系统常用技术及案例分析》示例源码
Stars: ✭ 446 (-6.89%)
Mutual labels:  taobao
Klaster
Declare RecyclerView adapters in a functional way, without boilerplate and subclassing. No compromises on flexibility. If it's possible to do something by subclassing, it's possible to do it with this library.
Stars: ✭ 373 (-22.13%)
Mutual labels:  recyclerview
Multiitem
一个优雅的实现多类型的RecyclerView类库 支持DataBinding Form表单录入 跨多个RecyclerView拖动
Stars: ✭ 381 (-20.46%)
Mutual labels:  recyclerview
Recyclerviewtemplate
One Template which solves all frequently used RecyclerViews Code Snippets
Stars: ✭ 404 (-15.66%)
Mutual labels:  recyclerview
Imageviewer
🔮图片浏览器,支持图片手势缩放、拖拽等操作,`自定义View`的模式显示,自定义图片加载方式,更加灵活,易于扩展,同时也适用于RecyclerView、ListView的横向和纵向列表模式,最低支持版本为Android 3.0及以上...
Stars: ✭ 363 (-24.22%)
Mutual labels:  recyclerview
Tvrecyclerview
TvRecyclerView--针对TV端特性进行的适配与开发
Stars: ✭ 453 (-5.43%)
Mutual labels:  recyclerview
Delegationadapter
一种优雅的方式来使用RecyclerView
Stars: ✭ 382 (-20.25%)
Mutual labels:  recyclerview
Alphabetindex Fast Scroll Recyclerview
A Powerful AlphabetIndex FastScroller Library for Android's RecyclerView!
Stars: ✭ 444 (-7.31%)
Mutual labels:  recyclerview
Y divideritemdecoration
A common RecyclerView divider , supports the LinearLayoutManager and the GridLayoutManager.
Stars: ✭ 373 (-22.13%)
Mutual labels:  recyclerview
Adapter
A quick adapter library for RecyclerView, GridView, ListView, ViewPager, Spinner
Stars: ✭ 376 (-21.5%)
Mutual labels:  recyclerview
Scrollingpagerindicator
Pager indicator inspired by Instagram. Lightweight and easy to set up.
Stars: ✭ 419 (-12.53%)
Mutual labels:  recyclerview
Familiarrecyclerview
一个如你熟悉ListView、GridView一样熟悉的RecyclerView
Stars: ✭ 372 (-22.34%)
Mutual labels:  recyclerview
Recycler Fast Scroll
Provides fast scroll and section idexer for recycler view
Stars: ✭ 445 (-7.1%)
Mutual labels:  recyclerview
Android Extensions
An Android library with modules to quickly bootstrap an Android application.
Stars: ✭ 356 (-25.68%)
Mutual labels:  recyclerview
Brvah kotlin
This is kotlin BRVAH Demo
Stars: ✭ 402 (-16.08%)
Mutual labels:  recyclerview
Dragdropswiperecyclerview
Kotlin Android library that extends RecyclerView to support gestures like drag & drop and swipe, among others. It works with vertical, horizontal and grid lists.
Stars: ✭ 469 (-2.09%)
Mutual labels:  recyclerview
Androidwithkotlin
🚀 These are android sample projects which are written in Kotlin. It covers video streaming, mp3 player, sqlite, location services, custom camera, o-notifications, simple compass etc.
Stars: ✭ 447 (-6.68%)
Mutual labels:  recyclerview
Recyclerview Gallery
Recyclerview-Gallery:This library shows you a gallery using RecyclerView.
Stars: ✭ 420 (-12.32%)
Mutual labels:  recyclerview

NestedRecyclerView

仿淘宝、京东首页,通过两层嵌套的RecyclerView实现tab的吸顶效果

现已提供Java和Kotlin两种版本,具体可查看项目代码。

项目效果展示:

背景

我们自己的商城的首页和淘宝、京东首页效果类似,上面为配置数据,中间是各种分类频道,下面是商品流数据,商品流部分支持左右横滑,分类频道是支持吸顶的。

最早是用CoordinatorLayout实现,在AppBarLayout下放一个RecyclerView,下面部分则放一个ViewPager,ViewPager里则是商品流的RecyclerView,CoordinatorLayout支持设置他的某个子View吸顶,这样基本能满足需求。

CoordinatorLayoutFix 中修复了一些体验问题,基本可以让这种实现满足商业性的项目需求。

调研

在调用了淘宝和京东的实现发现可以通过两层RecyclerView来实现。

image

可以看到京东首页的实现是上面这样的。

大致实现方式

  • 外部RecyclerView为ParentRecyclerView,将需要吸顶的悬浮效果的TabLayout和ViewPager作为ParentRecyclerView的一个item。
  • 内部RecyclerView为ChildRecyclerView,ParentRecyclerView和ChildRecyclerView相互协调:
    • 当ParentRecyclerView滚动到底部的时候,让ChildRecyclerView去滚动。
    • 当ChildRecyclerView滚动到顶部的时候,让ParentRecyclerView去滚动。

利用canScrollVertically这个方法来判断当前View是否滚动到底或者是否滚动到顶。

//ParentRecyclerView
   private boolean isScrollEnd() {
        //RecyclerView.canScrollVertically(1)的值表示是否能向上滚动,false表示已经滚动到底部
        return !canScrollVertically(1);
    }

//ChildRecyclerView
 boolean isScrollTop() {
        //RecyclerView.canScrollVertically(-1)的值表示是否能向下滚动,false表示已经滚动到顶部
        return !canScrollVertically(-1);
    }

ParentRecyclerView和ChildRecyclerView需要拿到对方的引用,以便能够协调滚动。

目前ChildRecyclerView是直接通过往上查找的方式来进行的。而ParentRecyclerView需要通过ViewPager来找到当前显示的是哪一个ChidRecyclerView。

//ChildRecyclerView
private ParentRecyclerView findParentRecyclerView() {
        ViewParent parentView = getParent();
        while (!(parentView instanceof ParentRecyclerView)) {
            parentView = parentView.getParent();
        }
        return (ParentRecyclerView)parentView;
    }
//ParentRecyclerView
   private ChildRecyclerView findNestedScrollingChildRecyclerView() {
        if(getAdapter()!= null && (getAdapter() instanceof MultiTypeAdapter)) {
            return ((MultiTypeAdapter)getAdapter()).getCurrentChildRecyclerView();
        }
        return  null;
    }

处理fling效果

在RecyclerView的onScrolled记录总的偏移,当ParentRecyclerView滑动到底部的时候,将多余的需要消费的总偏移转换成加速度,从而交给子View去Fling,反之,类型。

处理嵌套滚动

如果不处理嵌套滚动,在某些边界场景下,当我们滑动不松手时会出现无法滑动的问题。

另外

新增Tab折叠动画

关于

博客:https://blog.csdn.net/H_Gao

邮箱:[email protected]

License

Copyright 2018 JasonGaoH

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].