android - Animate TextViews one by one in Queue -


background: have view dynamically added textviews. graph/tree implementation each textview graph. maintaining adjacency list of these textviews(their ids maintained , can findviewbyid).

what want: have play button. want animate textviews such see root, children, next level. know: have made them invisible on pressing of play button. doing bfs such that

put root textview in queue make visible put direct children of root in queue while(!q.isempty()) {     remove first element queue     // animate     // after end of animation loop through adjacency list of node      // , put of children in queue } 

problem: whatever try, first element gets removed, q populated again children , animation of elements in qeueue starts @ once , finishes @ once. in other words, animation doesn't start till code finishes. have tried putting code population of children in onanimationend of animationlistener. doesn't work. tried thread.sleep, doesn't work.

i suppose problem treat startanimation() method sync, should finish after animation finishes. async: startanimation() changes view's state, telling him start animate himself @ next ui redraw loop, , goes further. that's why in app animations executed simultaneously. thread.sleep() won't work because freezes ui thread not changing behavior logic.

solution can following:

it possible specify delay, view should wait before starting animation, setstartoffset(offset) method of animation object. if each animation longs, example, 500 ms, animation object root view should have start offset 0, children - 500, children - 1000 etc.

you need create list of animation objects clones of initial animation, set start offsets , pass corresponding views.

animation anim = animationutils.loadanimation(this, r.anim...); // load initial animation xml  list<animation> anims = new arraylist<animation>; (int i=0; < treedepth; i++){     anims.set(i, anim.clone());     anims.get(i).setstartoffset(anim.getduration() * i);     (...){         // here apply created animation children of i-th level,         // can done later, no difference         view.startanimation(anims.get(i));     } } 

Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -