Git Product home page Git Product logo

expandablerecyclerview's Introduction

ExpandableRecyclerView

中文README

Design Sketch

Features:

  • Expand and close animations smoothly
  • Supports expanding only one Group
  • Support to expand and close all
  • Supports multiple types of items
  • Supports LinearLayoutManager and GridLayoutManager
  • Support sticky header
  • Expanded state saving and recovery (when switching between portrait and horizontal screens)
  • Support for Java project integration (>= v0.6.0)

Take a look

Download Url https://github.com/pokercc/ExpandableRecyclerView/releases

How to use:

  1. include dependence

Add it in your root build.gradle at the end of repositories:

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

last_version =

implementation("com.github.pokercc:ExpandableRecyclerView:${last_version}")
  1. Write code
  • Use ExpandableRecyclerView in your layout xml.
  • Inheriting ExpandableAdapter to realize your adapter.

More detail please refer demo

Attention:

  • Using StickyHeader,GroupViewHolder.itemView please set an opaque background, otherwise penetration will occur
  • ExpandableRecyclerView's height must set to match_parent or fixed size, Otherwise, the RecyclerView height may change during expansion and closure, causing problems for the execution of the animation

Design from: https://dribbble.com/shots/3253927-Accordion

Welcome to star or create issue.

expandablerecyclerview's People

Contributors

xigong93 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

expandablerecyclerview's Issues

java接入

你好,你这个效果实现的非常棒,能不能用Java版本写个接入文档啊

如何默认全部展开,并且禁止折叠

1.onBindGroupViewHolder 复写掉 groupViewHolder.itemView 的 click 事件 可以自定义自己的 头部点击事件,是不是只能这么做
2.如何实现默认全部展开

数据量大的时候如何避免快速滑动时数据错乱问题

RecyclerView避免快速滑动时数据错乱问题有一种方案是setHasStableIds(true)然后重写getItemId(position: Int)方法返回一个固定的id值,但是现在这个ExpandableRecyclerView组件有groupPosition和childPosition,没法直接重写getItemId(position: Int)方法,所以有避免快速滑动时数据错乱的更好的方案吗?或者如何保证getItemId(position: Int)返回唯一id值,且position能与groupPosition和childPosition对应上

pokercc

大神,你好,java项目如何使用,能出一个java版本的哈

如何删除单条?

  
        Handler().postDelayed(Runnable {
            val count = adapter.itemCount
            adapter.data.removeAt(0)
            adapter.notifyGroupRemove(0)
            adapter.notifyGroupRangeRemove(IntRange(0,count))

        },3000)
{
  "zone": [
    {
      "id": "bj",
      "name": "北京",
      "city": true,
      "sort": 1
    },
    {
      "id": "sh",
      "name": "上海",
      "city": true,
      "sort": 2
    }
  ],
  "university": [

    {
      "id": 133,
      "name": "复旦大学",
      "short": "复旦",
      "zone": "sh",
      "order": 2,
      "famous": true
    },
    {
      "id": 134,
      "name": "同济大学",
      "short": "同济",
      "zone": "sh",
      "order": 3
    },
    {
      "id": 135,
      "name": "华东师范大学",
      "short": "华师",
      "zone": "sh",
      "order": 4
    },
    {
      "id": 136,
      "name": "华东理工大学",
      "short": "华理",
      "zone": "sh",
      "order": 5
    },
    {
      "id": 137,
      "name": "上海外国语大学",
      "short": "上外",
      "zone": "sh",
      "order": 11
    },
    {
      "id": 138,
      "name": "东华大学",
      "short": "东华",
      "zone": "sh",
      "order": 7
    }
  ]
}

连续点击折叠展开会闪退

关于一个展开子项时比较严重的缺陷

如图,当recyclerview不够空间时,展开子项会直接把上面的项目顶上去,导致上面的项目不可视,能不能设置成不往上顶?如图所示,只在group项下直接展开。
Video_20210119_102635_913
Video_20210119_102725_389

Debuging Error

怎么解啊?

Could not determine the dependencies of task ':app:kaptDebugKotlin'.
> Could not resolve all files for configuration ':app:kotlinKaptWorkerDependencies'.
   > Could not find org.jetbrains.kotlin:kotlin-annotation-processing-gradle:1.4.21.
     Searched in the following locations:
       - https://dl.google.com/dl/android/maven2/org/jetbrains/kotlin/kotlin-annotation-processing-gradle/1.4.21/kotlin-annotation-processing-gradle-1.4.21.pom
       - https://jitpack.io/org/jetbrains/kotlin/kotlin-annotation-processing-gradle/1.4.21/kotlin-annotation-processing-gradle-1.4.21.pom
     Required by:
         project :app

Possible solution:
 - Declare repository providing the artifact, see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html

添加不了

implementation("pokercc.android.ExpandableRecyclerView:expandableRecyclerView:0.8.1")引入不了,资源找不到

V0.9.0,吸顶布局

在0.9.0版本调用notifyDataSetChanged()方法后,顶部布局不会闪烁了,但是也不会刷新了。。。我想点击顶部展开的时候顶部能够有变化,比如箭头的指向,但是展开列表时吸顶布局并没有发生变化

老哥,有个关于点击动画的问题您看看是否值得改进一下

问题描述:
在我使用您的库时,设置group项点击展开或关闭子项目的是否开启动画为false时,会导致group项的layout点击的水波纹消失,其实是有的,只是一瞬间,因为水波纹时长也因为我把动画设置为false,即动画显示时长为0而影响了吧,水波纹一闪就过了,只能看到一点点。

因为如果取消了动画,然后group项也没有水波纹的话,下面的子项出现或隐藏会显得很突兀。
主要还是因您所描述的那个bug,所以我就干脆直接关闭动画了。

您看看有没有值得改进一下?

Video_20210119_093418_470
Video_20210119_093434_186

吸顶切换时,部分控件闪烁(控件大小改变引起)

bug.mp4

如视频所示,当将要切换的GroupItem文字部分小于当前的,且后面有其它标签,标签会闪烁。
大概就是view宽度发生变化,重新计算前就开始绘制了造成的。
内部的TextView组件都会有这种情况,短文字变长文字都会闪烁。

快速连续点击父节点,字节点收到Onclick事件

复现步骤:
直接更改MarketsAdapter 里面的

onBindChildViewHolder
holder.itemView.setOnClickListener {
           MenuActivity.start(it.context)
        }

更改成

holder.itemView.setOnClickListener {
            Log.e("tag","childClick")
        }

快速连续点击父节点
发现有childClick日志输出

2020-12-15 14:23:19.403 31231-31231/com.expandablerecyclerview E/tag: childClick
2020-12-15 14:23:19.972 31231-31231/com.expandablerecyclerview E/tag: childClick
2020-12-15 14:23:20.565 31231-31231/com.expandablerecyclerview E/tag: childClick

为什么我想重写getGroupItemViewType方法却报错?

我想把索引为0的group区分开
@Override public int getGroupItemViewType(int groupPosition) { return (groupPosition==0)?0:1; }

最后却报错
java.lang.ClassCastException: com.magicalstory.cleaner.timer.main.list.adapter$ViewHolder_child cannot be cast to com.magicalstory.cleaner.timer.main.list.adapter$ViewHolder_group
at com.magicalstory.cleaner.timer.main.list.adapter.onBindGroupViewHolder(adapter.java:54)

即下面代码的类转换错误了,不知道为什么子项的viewholder为何出现在了group的事件中:
`
@OverRide
protected void onBindGroupViewHolder(ExpandableAdapter.ViewHolder viewHolder, int i, boolean b, List<?> list) {
functionsGroup functionsGroup = groupArrayList.get(i);
((ViewHolder_group) viewHolder).title.setText(functionsGroup.getTitle());
}

`

其他相关代码:
` @OverRide
public int getChildItemViewType(int groupPosition, int childPosition) {
return super.getChildItemViewType(groupPosition, childPosition);
}

@Override
public int getGroupItemViewType(int groupPosition) {
    return (groupPosition==0)?0:1;
}

@OverRide
protected ExpandableAdapter.ViewHolder onCreateChildViewHolder(ViewGroup viewGroup, int i) {
return new ViewHolder_child(LayoutInflater.from(context).inflate(R.layout.item_card_main_ver, viewGroup, false));
}

@Override
protected ExpandableAdapter.ViewHolder onCreateGroupViewHolder(ViewGroup viewGroup, int i) {
    Log.d("adapter", "i:" + i);
    return (i==0)?new ViewHolder_group(LayoutInflater.from(context).inflate(R.layout.item_group_main_no_title, viewGroup, false)):new ViewHolder_group(LayoutInflater.from(context).inflate(R.layout.item_group_main, viewGroup, false));
}`

百思不得其解,明明从来没有在onCreateGroupViewHolder方法返回ViewHolder_child啊,为什么在BindGroup会出现ViewHolder_child,而且我在没有重写获取group和child的viewtype方法前一切正常。

老哥,我又来了,发现了个终极的问题,可能是之前我提的问题的准确复现

问题描述:
当recyclerview设置为warp_content(这个肯定很多时候需要这样做的)
然后,当所有的groupitem全部关闭时,即recyclerview高度是最小的。

然后如下展开其中的groupitem,再闭合。
会发现动画显示不完全!就算不开延迟也明显肉眼可以感受到。

原因分析:
当groupitem展开时,recyclerview高度足够大,然后点击任意groupitem使其闭合,这时,recyclerview就直接刷新高度了(直接刷新为当正在执行groupitem已经关闭的高度),但是groupitem的sub_Items还在一一往上缩,但是当groupitem被点击时recyclerview已然早就缩到已经关闭的高度了,自然就会导致全部子item往上缩的时候全部都没被显示出来。

下面请看动画放慢的gif,可能比较大,我为了您看得清晰采用了比较高的清晰度,大概8MB

此外,提前祝您旧历新年快乐,新的一年事事顺利,身体健康,事业有成!

Video_20210209_102117_674

Add background

hello, I want to thank you for sharing the source code, your ExpandableRecyclerView works perfectly, thank you for the effort made.
on the other hand I have a question about the backround, I try to add a drawable border to my childitem but it did not work for me.
could you give me advice so that I can adapt your recyclerview to my needs and thank you in advance.
waiting for a response from you, please accept my most distinguished greetings

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.