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

Not showing any animation #30

Open hadifar opened 9 years ago

hadifar commented 9 years ago

Hi , I follow your instruction But no animation appear. no exception no error

here is my recyclerView :

recyclerView = (RecyclerView) findViewById(R.id.headersList); LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this); recyclerView.setLayoutManager(linearLayoutManager); recyclerView.addItemDecoration(new DividerItemDecoration(getResources().getDrawable(R.drawable.empty_divider))); recyclerView.setItemAnimator(new SlideInLeftAnimator()); recyclerView.getItemAnimator().setChangeDuration(1000); recyclerView.getItemAnimator().setMoveDuration(1000); adapter = new HeadersAdapter(); recyclerView.setAdapter(adapter);

and here is my adapter :

public class HeadersAdapter extends RecyclerView.Adapter<HeadersAdapter.ViewHolder> {

    private List<LawBookHeader> items;

    public HeadersAdapter() {
        items = new BundledDataBaseManager().getLawHeaderChilds(parentHeader.getId());
    }

    @Override
    public HeadersAdapter.ViewHolder onCreateViewHolder(ViewGroup viewGroup, final int itemType) {

        View rootView = getLayoutInflater().inflate(layoutRes, viewGroup, false);
        rootView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                LawBookHeader item = getItem(recyclerView.getChildAdapterPosition(v));
                if (item.hasChild()) {
                    startActivity(createIntent(LawBookHeaderActivity.this, item));
                } else if (item.hasContent()) {
                    startActivity(LawBookItemsActivity.createIntent(LawBookHeaderActivity.this, item));
                }
            }
        });

        return new ViewHolder(rootView);
    }

    public LawBookHeader getItem(int position) {
        return items.get(position);
    }

    @Override
    public long getItemId(int position) {
        return getItem(position).getId();
    }

    @Override
    public int getItemCount() {
        return items.size();
    }

    public class ViewHolder extends AnimateViewHolder {
        public TextView title;
        public TextView itemsIncluding;

        public ViewHolder(View itemView) {
            super(itemView);
            title = (TextView) itemView.findViewById(R.id.header);
            itemsIncluding = (TextView) itemView.findViewById(R.id.itemsIncluding);
        }

        @Override
        public void animateRemoveImpl(ViewPropertyAnimatorListener listener) {
            ViewCompat.animate(itemView)
                    .translationY(-itemView.getHeight() * 0.3f)
                    .alpha(0)
                    .setDuration(300)
                    .setListener(listener)
                    .start();
        }

        @Override
        public void preAnimateAddImpl() {
            ViewCompat.setTranslationY(itemView, -itemView.getHeight() * 0.3f);
            ViewCompat.setAlpha(itemView, 0);
        }

        @Override
        public void animateAddImpl(ViewPropertyAnimatorListener listener) {
            ViewCompat.animate(itemView)
                    .translationY(0)
                    .alpha(1)
                    .setDuration(300)
                    .setListener(listener)
                    .start();
        }

    }
}
alizarei95 commented 9 years ago

same problem here , any idea ?

wasabeef commented 9 years ago

@AmirHadifar @Pishtaz

Hi,

is it not running in the following call? notifyItemInserted(position); and notifyItemRemoved(position);

alizarei95 commented 9 years ago

do I need this for adapter animation ?

Sent from Windows Mail

From: Daichi Furiya Sent: ‎Monday‎, ‎September‎ ‎7‎, ‎2015 ‎10‎:‎11‎ ‎AM To: wasabeef/recyclerview-animators Cc: Ali Zarei

@AmirHadifar @Pishtaz

Hi,

is it not running in the following call? notifyItemInserted(position); and notifyItemRemoved(position);

— Reply to this email directly or view it on GitHub.

wasabeef commented 9 years ago

@Pishtaz

ok, just sent.

Hhwhiskey commented 8 years ago

I have the same issue. When I run my code with notifyDataSetChanged(), it's killing my animations, nothing happens, the item is just instantly removed. When I run my code without notifyDataSetChanged(); it shows the animation, but does not update the data. Is there a fix for this?

wasabeef commented 8 years ago

@Pishtaz @Hhwhiskey

Please use the following
notifyItemChanged(int) notifyItemInserted(int) notifyItemRemoved(int) notifyItemRangeChanged(int, int) notifyItemRangeInserted(int, int) notifyItemRangeRemoved(int, int)

If you want your animations to work, do not rely on calling notifyDataSetChanged(); as it is the RecyclerView's default behavior, animations are not triggered to start inside this method.