I have a special animation that populates the cards for my RecyclerView
. The animation works good (at least for inflating). I don't want this animation to be used after initial inflation. In other words, I don't want any animation for scrolling (or really any action by the user after initial inflation of enough cards to fill the user's screen). I can't figure out how to grab the position number -or- turn off animation after populating -or- any way to do this. My animation is called in the adapter. Here's the adapter code that I am using to set the animation.
public class TagAdapter extends RecyclerView.Adapter<TagAdapter.ViewHolder>{
private ArrayList<TagDataModel> dataSet;
private Context context;
public TagAdapter (ArrayList<TagDataModel> ds, Context ctx){
this.dataSet =ds;
this.context =ctx;
}
class ViewHolder extends RecyclerView.ViewHolder {
TextView tv_tag;
ArrayList<TagDataModel> dataSet = new ArrayList<>();
Context context;
CardView card;
ViewHolder(View itemView, Context ctx, ArrayList<TagDataModel> ds) {
super(itemView);
this.dataSet = ds;
this.context =ctx;
this.tv_tag = (TextView) itemView.findViewById(R.id.tv_cardTag);
this.card = (CardView) itemView.findViewById(R.id.card_view_tag);
}
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType){
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.card_tag, parent, false);
ViewHolder viewHolder = new ViewHolder(view, context, dataSet);
return viewHolder;
}
@Override
public void onBindViewHolder(final ViewHolder holder, @SuppressLint("RecyclerView") final int position) {
final int activePosition = context.getSharedPreferences("userPrefs", Context.MODE_PRIVATE).getInt("np_tag", 0);
TextView tv_tag = holder.tv_tag;
CardView card = holder.card;
tv_tag.setText(dataSet.get(position).getTag());
});
animate(holder.itemView, position); //animate only first page UPDATE
}
@Override
public int getItemCount() {
return dataSet.size();
}
private void animate(View view, final int pos) {
view.animate().cancel();
view.setTranslationY(100);
view.setAlpha(0);
view.animate().alpha(1.0f).translationY(0).setDuration(300).setStartDelay(pos *100);
}