RecyclerView expandable cardView

后端 未结 3 711
走了就别回头了
走了就别回头了 2021-01-11 21:47

I make small project with RecyclerView with CardView items inside. I created expandable card (expanded by pressing on small button inside the card). Each card always contain

相关标签:
3条回答
  • 2021-01-11 22:16

    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.

    0 讨论(0)
  • 2021-01-11 22:23

    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 :-)

    0 讨论(0)
  • 2021-01-11 22:31

    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

    0 讨论(0)
提交回复
热议问题