wasabeef / recyclerview-animators

An Android Animation library which easily add itemanimator to RecyclerView items.
Apache License 2.0
11.51k stars 1.98k forks source link

how to animate list on populate #9

Open EloneMusk opened 9 years ago

EloneMusk commented 9 years ago

How do I animate the list when my activity starts and list populates

faizsiddiqui commented 9 years ago

Try this.. only AlphaInAnimationAdapter working in this case. I too facing this issue.

mAdapter = new CardView(titles);
AlphaInAnimationAdapter alphaAdapter = new AlphaInAnimationAdapter(mAdapter);
alphaAdapter.setDuration(1000);
mRecyclerView.setAdapter(alphaAdapter);
wasabeef commented 9 years ago

What you have set?

faizsiddiqui commented 9 years ago

CardView with images, some text. Do you want me to paste Adapter code? screenshot_1

wasabeef commented 9 years ago

Yes. please show me the code.

faizsiddiqui commented 9 years ago
public class CardView extends RecyclerView.Adapter<CardView.ViewHolder> {

    public String[] titles, descriptions, images;
    OnItemClickListener mItemClickListener;
    ImageLoader mImageLoader;

    public CardView(String[] titles, String[] descriptions, String[] images) {
        this.titles = titles;
        this.descriptions = descriptions;
        this.images = images;
    }

    @Override
    public CardView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.card_view, parent, false);
        mImageLoader = VolleySingleton.getInstance().getImageLoader();
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(CardView.ViewHolder holder, int position) {
        holder.cardViewTitle.setText(titles[position]);
        holder.cardViewText.setText(descriptions[position]);
        holder.cardNetworkImageView.setImageUrl(images[position], mImageLoader);
    }

    @Override
    public int getItemCount() {
        return titles.length;
    }

    public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {

        NetworkImageView cardNetworkImageView;
        TextView cardViewTitle, cardViewText;

        public ViewHolder(View itemView) {
            super(itemView);
            cardNetworkImageView = (NetworkImageView) itemView.findViewById(R.id.cardViewImage);
            cardViewTitle = (TextView) itemView.findViewById(R.id.cardViewTitle);
            cardViewText = (TextView) itemView.findViewById(R.id.cardViewText);
            itemView.setOnClickListener(this);
        }

        @Override
        public void onClick(View v) {
            if (mItemClickListener != null) {
                mItemClickListener.onItemClick(v, getPosition());
            }
        }
    }

    public interface OnItemClickListener {
        public void onItemClick(View view, int position);
    }

    public void SetOnItemClickListener(OnItemClickListener mItemClickListener) {
        this.mItemClickListener = mItemClickListener;
    }

}
hbb20 commented 9 years ago

@abhi98228 and @faizsiddiqui ,Let me understand your question. I think you can see the animation while scrolling, but you also want to see the animation when the activity is started? Right?(No?, please make me clear) but If so, let me try to help. If your list data is already loaded. (I means when you do not need to make http call to receive list data). In that case ,Animation would be fast enough so that you might not notice them. Please try inside your onViewCreate() or equivalent method (where you assign view object from XML file's rootView.)

 mRecyclerView=(RecyclerView)rootView.findViewById(R.id.myRecyclerView);
 recyclerView.post(new Runnable() {
            @Override
            public void run() {
                mAdapter = new CardView(titles);
                AlphaInAnimationAdapter alphaAdapter = new AlphaInAnimationAdapter(mAdapter);
                mRecyclerView.setAdapter(alphaAdapter);      
            }
        });

If still its fast, try by adding timer delay. Check What does post(runnable) do?

faizsiddiqui commented 9 years ago

@hbb20 No, I'm not even seeing animation on Scrolling. Only "AlphaInAnimationAdapter" working.

dongseok0 commented 9 years ago

Yeah same here. only AlphaInAnimationAdapter work. And others work in 1.1.0 version.