0

I have to implement a transition of either a viewpager o a recyclerview, not sure yet which could fit better. The idea is to expand de ViewPager or Recycler and show more information when this is expanded and less information when is collapsed.

Expand and collapse with MotionLayout is quite easy however I cannot find the approach for animate and change the content shown in each element of the the adapter.

is it posible to animate the content of an adapter simultaneously?

Jose M Lechon
  • 5,766
  • 6
  • 44
  • 60

1 Answers1

0

I an ugly solution for you. I use a recycler-view that contains some motion layouts. There is an expanded state and a collapsed state, we only want one expanded at a time.

A method to close positions in the fragment/activity

fun collapseMotionLayout(positions: IntArray){ 
    positions.forEach { position -> 
        recyclerView.findViewHolderForAdapterPosition(position)?.let { childView ->
           //transitionToEnd() or transitionToStart() or toggleUI() or whatever
           (childView.itemView.findViewWithTag("motionlayout") as? MotionLayout)?.collapse()
    }
}

And then a fragment/activity call back in the motion layout's TransitionListener that you'll define in the viewholder (we use a custom view)

tListener = object: TransitionListener{
    override onCompleted(){  
           callBack.invoke(positionsForAnimation())
    }
}

I only see this collapse a single motion layout at a time. I have found that multiple motion layouts running simultaneously will will cause performance issues.

Airagale
  • 226
  • 1
  • 3
  • 19