title: Android recyclerview issue with animations
body: <p>I'm trying to make cardviews in recyclerview expand. I got the expanding part working, but when adding transition to it, some visual bugs start to occur. The transitions works fine, when there are no off-screen items, but when I add more than (in my case) 4 items to the recyclerview, it starts to occur.</p>
  
  <p><a href="https://i.stack.imgur.com/5mOU3.gif" rel="noreferrer">GIF with 4 items</a></p>
  
  <p><a href="https://i.stack.imgur.com/XcL68.gif" rel="noreferrer">GIF with more than 4 items</a></p>
  
  <p>The cardview expanding works fine with more than 4 items when I disable the transition animation. I think the problem is related to positions changing, but I can't find any solution to the problem.</p>
  
  <p>The guide I used to implement the cardview expanding can be found here: <a href="https://stackoverflow.com/a/38623873/6673949">https://stackoverflow.com/a/38623873/6673949</a></p>
  
  <p>And my complete recyclerview adapter</p>
  
  <pre><code>public class BasketRecyclerAdapter extends RecyclerView.Adapter&lt;BasketRecyclerAdapter.CustomViewHolder&gt; {
  private String letter;
  private Context mContext;
  private ColorGenerator generator = ColorGenerator.MATERIAL;
  private List&lt;Basket&gt; baskets;
  private int mExpandedPosition = -1;
  private RecyclerView r1;
  
  public BasketRecyclerAdapter(Context context, List&lt;Basket&gt; baskets, RecyclerView r1) {
      this.mContext = context;
      this.baskets = baskets;
      this.r1 = r1;
  
  }
  
  @Override
  public CustomViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
      View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.basket_menu_item, null);
      CustomViewHolder viewHolder = new CustomViewHolder(view);
      return viewHolder;
  }
  
  @Override
  public void onBindViewHolder(final BasketRecyclerAdapter.CustomViewHolder holder, final int position) {
  
      String basketName = baskets.get(position).getBasketName();
  
      holder.basketName.setText(basketName);
  
      letter = "" + basketName.charAt(0);
  
      TextDrawable drawable = TextDrawable.builder()
              .buildRound(letter, generator.getColor(basketName));
  
  
      holder.imageLetter.setImageDrawable(drawable);
  
      final boolean isExpanded = position == mExpandedPosition;
      holder.expandedLayout.setVisibility(isExpanded?View.VISIBLE:View.GONE);
      holder.itemView.setActivated(isExpanded);
      holder.itemView.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              mExpandedPosition = isExpanded ? -1:position;
              if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.KITKAT) {
                  TransitionManager.beginDelayedTransition(r1);
              }
              notifyDataSetChanged();
          }
      });
  
  
  }
  </code></pre>
  
  <p>What can be done to solve the problem? Thanks.</p>
  
  <p>Edit: I tried to get it to work by using just ListView instead of RecyclerView, but ListView adapter doesn't expand with same code - will try to figure out why.</p>
  
  <p>Edit2: Got it working by using another library called "ExpandableLayout" but still can't seem to figure out why is it not working without additional libraries.</p>