Android: Start animation after fragment is completely loaded -


i have fragment has animation of textview fadein. animation must start after time delay 2 seconds after fragment loaded. wrote code this. animation part done , view rendered. how can load fragment , after time delay start animation

my code below: note: class extends fragment

animation animfadein; menuclickhelper mclickhelper; textview tv;  @override public view oncreateview(layoutinflater inflater, viewgroup container,         bundle savedinstancestate) {     final view rootview = inflater.inflate(r.layout.fragment_main_menu,             container, false);      mclickhelper = new menuclickhelper(rootview, getfragmentmanager());      tv = (textview) rootview.findviewbyid(r.id.tvpresentation);     animfadein = animationutils.loadanimation(getactivity()             .getapplicationcontext(), r.anim.fade_in);      animfadein.setanimationlistener(new animationlistener() {          @override         public void onanimationstart(animation animation) {             // todo auto-generated method stub          }          @override         public void onanimationrepeat(animation animation) {             // todo auto-generated method stub          }          @override         public void onanimationend(animation animation) {             if (animation == animfadein) {                 toast.maketext(getactivity().getapplicationcontext(),                         "animation stopped", toast.length_short).show();             }         }     });      try {         thread.sleep(2000);         tv.startanimation(animfadein);     } catch (interruptedexception e) {         // todo auto-generated catch block         e.printstacktrace();     }     return rootview; } 

thread.sleep(2000); dont block main using sleep method instead can use handler class , use postdelay delay animation:

sample:

change this:

 try {     thread.sleep(2000);     tv.startanimation(animfadein); } catch (interruptedexception e) {     // todo auto-generated catch block     e.printstacktrace(); } 

to

new handler().postdelayed(new runnable() {   @override   public void run() {     tv.startanimation(animfadein);   } }, 2000); //will start animation in 2 seconds 

Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -