android - Animating 3 parts of a view -
android - Animating 3 parts of a view -
i trying create app view that, when presented subtraction problem, show animation of growing rectangle (or fat line) crawls number line integer.
i have things set click "show me!" , bars drawn along number line showing minuend, subtrahend , difference, i'd able have positive number's rectangle crawl in positive direction, negative 0 in negative direction.
in looking through documentation there seem several different ways go this. hoping can suggest way that's reasonably simple novice implement. here different approaches i've found:
this seems much person's want have bar graph bars "pop up," doesn't have answer. android animated bar chart (invalidate())
i've perused http://developer.android.com/guide/topics/resources/drawable-resource.html -- don't have "drawable" because it's beingness drawn in view. i'm thinking of making rest of number line background bitmap per android view.getdrawingcache returns null, null want 3 rectangles (for minuend, subtrahend , difference).
i have thought of making series of rectangle drawables , showing them frame-by-frame show growth.
i have looked @ animation @ specified rate using canvas / ondraw cannot discern code wrap in "if" statement, if in fact problem re-drawing...
i looked @ using paths -- , set next code together. if direction matters, seems should able slow things downwards , watch path going in direction, it's instantaneous. found saw illustration @ http://www.curious-creature.org/2013/12/21/android-recipe-4-path-tracing/
if (minuendlength > 0) // start @ 0 , go minuend length { path.addrect(interpx(0), yposition(40), interpx(minuendlength), yposition(43) , path.direction.cw); // interpx lets me number on number line should align with; //yposition percent of way downwards screen. canvas.drawpath(path,minuendpaint); // seems same drawrect -- instantaneous. }
(the number line in 'background' code follows, different options different sized integers entered:
if ( (minuendlength <10 && subtrahendlength <10 ) && (minuendlength >-10 && subtrahendlength >-10 ) ) { this.setlinedimension(10); // default super.ondraw(canvas); canvas.drawline(interpx(-this.getlinedimension()), yposition(52 ), interpx(this.getlinedimension()), yposition(52), axispaint); int step = this.getlinedimension()/5; // you're not writing *all* numbers // when come in numbers , create own number line. // paints little hatch marks (int x = -this.getlinedimension(); x <= this.getlinedimension(); x+=step/2) canvas.drawline(interpx(x), yposition(52), interpx(x), yposition(53) , littleaxispaint); // draw numbers on hatch marks textpaint.settextalign(paint.align.center); (int x = -this.getlinedimension() + step; x < this.getlinedimension(); x += step) { canvas.drawtext(integer.tostring(x), interpx(x), yposition(56), textpaint); } }
i ended doing using runnables.
animate.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { if ( ((addend1 > 0) && (addend2 < 0)) ) { tempnum1 =addend1 ; tempnum2 = addend2; h.post(shrink1bigger); } else if (addend1 < 0 && addend2 > 0) { tempnum1 =addend1 ; tempnum2 = addend2; h.post(shrink2bigger); } } }); private runnable shrink2bigger = new runnable(){ @override public void run() { tempnum1+=1; tempnum2-=1; shrinkdraw(); log.i("watchanimactivity", "tempnum1 " + tempnum1); h.postdelayed(shrink2bigger, 500); checktemp(shrink2bigger); }}; private void shrinkdraw() { numline.setfirstnum(tempnum1); numline.setnextnum(tempnum2); numline.invalidate(); } public void checktemp(runnable shrink) { log.i("watchanimactivity", "tempnum1 in checktemp " + tempnum1); if (tempnum1 ==0 || tempnum2==0) h.removecallbacks(shrink); }
android animation view android-drawable runnable
Comments
Post a Comment