简体   繁体   中英

RecyclerView custom animation while scrolling

I have a RecyclerView with multiple CardViews . These I expand and collapse by using this code in my onBindViewHolder :

@Override
public void onBindViewHolder(final ViewHolder holder, int position) {
 
    holder.cardView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (holder.hiddenLayout.getVisibility() == View.VISIBLE) {
                TransitionManager.beginDelayedTransition(holder.cardView,
                        new AutoTransition());
                holder.hiddenLayout.setVisibility(View.GONE);
            } else {
                TransitionManager.beginDelayedTransition(holder.cardView,
                        new AutoTransition());
                holder.hiddenLayout.setVisibility(View.VISIBLE);
            }
        }
    });
}

My Problem is, when I scroll while the animation takes place the cards get badly brought up and become extremely warped. How can I avoid that to happen?

This is a common mistake.handling your onclick listener inside onbindviewholder method is not the best idea.try to handle your click listeners in your viewholder class.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM