android - Stop animation after recyclerview inflates screen -


i have special animation populates cards recyclerview. animation works (at least inflating). don't want animation used after initial inflation. in other words, don't want animation scrolling (or action user after initial inflation of enough cards fill user's screen). can't figure out how grab position number -or- turn off animation after populating -or- way this. animation called in adapter. here's adapter code using set 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 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); } 

remove current animation bindviewholder , use custom itemanimator , override animateadd method. can find more here

this should give desired result.

public class myitemanimator extends defaultitemanimator {   @override     public boolean animateadd(viewholder viewholder) {         animate(viewholder.itemview);         return true;     }  private void animate(view view) {     view.settranslationy(100);     view.setalpha(0);     view.animate().alpha(1.0f).translationy(0).setduration(300); }   } 

now set item animator recyclerview.

recyclerview.setitemanimator(new myitemanimator());

try :)


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -