android - Tween animation on a Canvas in a custom View -


i have class extends view, , draw need inside canvas in ondraw() method, this:

protected void ondraw(canvas canvas) {         synchronized (this) {                 float h = mheight;                 float w = mwidth;                  canvas.drawcolor(color.white);                  float roadline= (85.0f/100.0f)*h;                  canvas.drawbitmap(mtop, 0, roadline-mtop.getheight(), null);                  //this i'd animate                 canvas.drawbitmap(msmoke);          }     } 

how make animation (tween animation) draw in here?

you can't draw imageview inside ondraw() method of class.

this more you're after.

public class simpleanimation extends activity {  sprite sprite;  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);      sprite = new sprite(this);     setcontentview(sprite); }  class sprite extends imageview {      bitmap bitmap;     paint paint;     rotateanimation rotate;     alphaanimation blend;     scaleanimation scale;     animationset spriteanimation;      float centerx;     float centery;     float offsetx;     float offsety;      public sprite(context context) {         super(context);          bitmap = bitmapfactory.decoderesource(getresources(), r.drawable.icon);         offsetx = bitmap.getwidth() / 2;         offsety = bitmap.getheight() / 2;          paint = new paint();         paint.setantialias(true);         paint.setfilterbitmap(true);     }      @override     protected void ondraw(canvas canvas) {         super.ondraw(canvas);          if (spriteanimation == null) {             centerx = canvas.getwidth() / 2;             centery = canvas.getheight() / 2;             createanimation(canvas);         }         canvas.drawbitmap(bitmap, centerx - offsetx, centery - offsety, paint);     }      private void createanimation(final canvas canvas) {          rotate = new rotateanimation(0, 360, centerx, centery);         rotate.setrepeatmode(animation.reverse);         rotate.setrepeatcount(animation.infinite);         scale = new scaleanimation(0, 2, 0, 2, centerx, centery);         scale.setrepeatmode(animation.reverse);         scale.setrepeatcount(animation.infinite);         scale.setinterpolator(new acceleratedecelerateinterpolator());          spriteanimation = new animationset(true);         spriteanimation.addanimation(rotate);         spriteanimation.addanimation(scale);         spriteanimation.setduration(10000l);          startanimation(spriteanimation);      }   } } 

Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -