1

Previously, I implemented Google+ card liked animation (Video), by using technique mentioned in New Google Now and Google+ card interface

  1. Override LinearLayout's onGlobalLayout to start animation, so that when activity first launched, we can see the slide up animation of cards.
  2. Override ScrollView's onScrollChanged to start animation, so that during scrolling, we can see the newly visible cards being animated.

So far, I don't see any technique from RecylerView's example.

I was wondering, without using LinearLayout and ScrollView, can with achieve the same outcome, by using RecylerView? Is there any code example available? (So far, I unable to find one yet)

Community
  • 1
  • 1
Cheok Yan Cheng
  • 47,586
  • 132
  • 466
  • 875

1 Answers1

0

Add these lines in RecyclerView 's adaptor. Make a Variable for Each card i.e(convertView) here and initialise it.

int mLastPosition = 0;
public static class ViewHolder extends RecyclerView.ViewHolder {
 TextView card_head, card_body;
 View convertView;
      @SuppressLint("NewApi")
      public ViewHolder(View v) {
       super(v);
      convertView = v;
    }
 }

Bind you view by position

@Override
public void onBindViewHolder(final ViewHolder holder, final int position) {

// do your thing here

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) {
        float initialTranslation = (mLastPosition <= position ? 150f
                : -150f);

        holder.convertView.setTranslationY(initialTranslation);
        holder.convertView.animate()
                .setInterpolator(new DecelerateInterpolator(1.0f))
                .translationY(0f).setDuration(900l).setListener(null);
    }
    // Keep track of the last position we loaded
    mLastPosition = position;
}

here , you have to animate the who view it calls onBindViewHolder method when new card is created animate the whole view customize it.

Hemant Shori
  • 2,463
  • 1
  • 22
  • 20