android – 如何在Canvas中旋转圆形动画

android – 如何在Canvas中旋转圆形动画,第1张

概述我想在 android上的画布中连续旋转圆圈.我正在使用画布绘制圆圈,我不断旋转圆圈.如果可能的话,这是可能的 用代码或示例可以帮助我非常感谢! 这是我在画布上绘制圆圈的代码: import android.app.Activity; import android.content.Context; import android.graphics.Canvas; import 我想在 android上的画布中连续旋转圆圈.我正在使用画布绘制圆圈,我不断旋转圆圈.如果可能的话,这是可能的
用代码或示例可以帮助我非常感谢!

这是我在画布上绘制圆圈的代码:

import androID.app.Activity;    import androID.content.Context;    import androID.graphics.Canvas;    import androID.graphics.color;    import androID.graphics.Paint;    import androID.os.Bundle;    import androID.vIEw.VIEw;    public class AnimationActivity extends Activity {        /** Called when the activity is first created. */        @OverrIDe        protected voID onCreate(Bundle savedInstanceState)        {            super.onCreate(savedInstanceState);            setContentVIEw(new SampleVIEw(this));        }    public class SampleVIEw extends VIEw    {        public SampleVIEw(Context context)        {            super(context);            // Todo auto-generated constructor stub        }        @OverrIDe        protected voID onDraw(Canvas canvas)        {             Paint mPaint = new Paint();             mPaint.setStyle(Paint.Style.stroke);             mPaint.setstrokeWIDth(10);             mPaint.setcolor(color.RED);             canvas.drawCircle(75,75,mPaint);        }    }  }

提前致谢!

解决方法 您可以使用动画旋转您绘制的圆(使用Canvas).以下代码有效.我修改了你的代码并添加了必要的更改.

import androID.app.Activity;import androID.content.Context;import androID.graphics.Canvas;import androID.graphics.color;import androID.graphics.Paint;import androID.os.Bundle;import androID.vIEw.VIEw;public class AnimationActivity extends Activity {    public class SampleVIEw extends VIEw {        Paint mPaint = new Paint();        private Animation anim;        public SampleVIEw(Context context) {            super(context);            mPaint.setStyle(Paint.Style.stroke);            mPaint.setstrokeWIDth(10);            mPaint.setcolor(color.RED);        }        private voID createAnimation(Canvas canvas) {            anim = new RotateAnimation(0,360,getWIDth()/2,getHeight()/2);            anim.setRepeatMode(Animation.RESTART);            anim.setRepeatCount(Animation.INFINITE);            anim.setDuration(10000L);            startAnimation(anim);       }        protected voID onDraw(Canvas canvas) {             int cx = getWIDth()/2; // x-coordinate of center of the screen             int cy = getHeight()/2; // y-coordinate of the center of the screen             // Starts the animation to rotate the circle.             if (anim == null)                createAnimation(canvas)             canvas.drawCircle(cx,cy,150,mPaint); // drawing the circle.        }            }    protected voID onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         setContentVIEw(new SampleVIEw(this));    }}

请享用!

总结

以上是内存溢出为你收集整理的android – 如何在Canvas中旋转圆形动画全部内容,希望文章能够帮你解决android – 如何在Canvas中旋转圆形动画所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1126614.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-30
下一篇2022-05-30

发表评论

登录后才能评论

评论列表(0条)

    保存