add animation to adapter of recyclerview

public class guide_adapter extends RecyclerView.Adapter<guide_adapter.MyViewHolder> { private List<gide_model> itemList; private int lastPosition = -1; Context context; public class MyViewHolder extends RecyclerView.ViewHolder { LinearLayout container; public MyViewHolder(View view) { super(view); container= (LinearLayout) view.findViewById(R.id.item_main); } } public guide_adapter(Context c,List<gide_model> moviesList) { this.itemList = moviesList; context=c; } @Override public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { View itemView = LayoutInflater.from(parent.getContext()) .inflate(R.layout.item_giude, parent, false); return new MyViewHolder(itemView); } @Override public void onBindViewHolder(MyViewHolder holder, int position) { // categModel productData = itemList.get(position); // holder.productTitle.setText(productData.getTitle()); // holder.productImage.setImageResource(productData.getImageUrl()); setAnimation(holder.container, position); } private void setAnimation(View viewToAnimate, int position) { // If the bound view wasn't previously displayed on screen, it's animated if (position > lastPosition) { Animation animation = AnimationUtils.loadAnimation(context, android.R.anim.slide_in_left); viewToAnimate.startAnimation(animation); lastPosition = position; } } @Override public int getItemCount() { return itemList.size(); } }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.