2

I'am trying to achieve expand and collapse animation in RecyclerView and tried this solution but it's have a lot of problems and i can't use it anymore, Also o tried a lot of solutions but it's not working as requested from customer like scale the view using this to collapse the view:

view.animate().scaleY(1 / item.getHeight()).setDuration(300).withEndAction(new Runnable() {
    @Override
    public void run() {
        item.setVisibility(View.GONE);
    }
});

I want the animation exactly like this:

Image

Is there any way to do this?

Community
  • 1
  • 1

1 Answers1

0

you can always use a 3rd party library for a nice implementation , but I use this way to reduce the amount of libraries in my app .

 int mExpandedPosition = -1;
 int OldOpen = -1;
 @Override
        public void onBindViewHolder(final Example.ViewHolder holder, final int position) {


//what ever your bind logic goes here

            holder.textViewKey.setText(allData.get(position).get("key"));

//expanding this view will collapse any other one open`

            final boolean isExpanded = position==mExpandedPosition;
            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                   OldOpen = mExpandedPosition;
                    if (isExpanded == true) {
                        mExpandedPosition = -1;
                    } else {
                        mExpandedPosition = position;
                    }
                    TransitionManager.beginDelayedTransition(CompanyDetailsRecycler);
                    if (OldOpen != -1)
                        notifyItemChanged(OldOpen);
                    notifyItemChanged(position);
                }
            });
Sarah Maher
  • 790
  • 1
  • 10
  • 21