
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,roadline-mtop.getHeight(),null); //this is what I'd like to animate canvas.drawBitmap(mSmoke); } } 如何在此处制作动画(补间动画)?
解决方法 您无法在另一个类的onDraw()方法中绘制ImageVIEw.这可能是你所追求的更多.
public class SimpleAnimation extends Activity {Sprite sprite;@OverrIDeprotected 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,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); } }} 总结 以上是内存溢出为你收集整理的android – 自定义视图中的画布上的Tween动画全部内容,希望文章能够帮你解决android – 自定义视图中的画布上的Tween动画所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)