RecyclerView expandable cardView

China☆狼群 提交于 2019-12-01 03:31:10

What tecnique are you using in order to do that?

I was in the same situation but for me the problem were these functions ExpandAndCollapseViewUtil.expand() and ExpandAndCollapseViewUtil.collapse() from this tutorial Diseño Android: Tarjetas con CardView so I didn't use it. Instead of that I just show/hide the view of the cardview without any animation.

Mahdi Astanei

You can use this lib instance your self developed way, try this:

STEP 1: Add below dependency to your build.gradle file:

**compile 'com.github.traex.expandablelayout:library:1.2.2'** use instead of
 compile 'com.github.traex.expandablelayout:library:1.3'

STEP 2: Add below View to Your card layout ,card_layout Must be look like this:

<com.andexert.expandablelayout.library.ExpandableLayout
    android:id="@+id/row_0"
    xmlns:expandable="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    expandable:headerLayout="@layout/YOUR_CARD_VIEW_UI"
    expandable:contentLayout="@layout/YOUR_CARD_VIEW_EXPANDED_UI"/>

STEP 3: In your define of RecyclerView remember to:

recList.setItemViewCacheSize(ITEMS_COUNT);

Feel free to Ask :-)

I had the same problem and solved it by putting following code (Kotlin) in the ViewHolder

    if (expandableView.isVisible) {
        val recyclerView = containerView?.parent as RecyclerView
        recyclerView.adapter.notifyItemChanged(adapterPosition)
        recyclerView.smoothScrollToPosition(adapterPosition)
    }

As you see before scroll to a position I notified the adapter that the item on this position was changed. And I only do this if the view became visible

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!