在android中以固定的圆形路径移动对象

在android中以固定的圆形路径移动对象,android,animation,math,android-animation,Android,Animation,Math,Android Animation,我想把一个物体沿着固定的圆形轨道移动,就像行星绕太阳运行一样 根据我的研究,以下是链接: 然而,它不起作用 以下是更新的代码: public class MainActivity extends Activity { ourView v; Bitmap tball; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); v = new ou

我想把一个物体沿着固定的圆形轨道移动,就像行星绕太阳运行一样

根据我的研究,以下是链接: 然而,它不起作用

以下是更新的代码:

public class MainActivity extends Activity {
ourView v;

Bitmap tball;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    v = new ourView(this);

    setContentView(v);
    tball = (BitmapFactory.decodeResource(getResources(),
            R.drawable.blueball));

}

protected void onPause() {
    super.onPause();
    v.pause();
}

protected void onResume() {
    super.onResume();
    v.resume();
}

public class ourView extends SurfaceView implements Runnable {
    Thread t;
    SurfaceHolder holder;
    Boolean isitok = false;

    public ourView(Context context) {
        super(context);
        // TODO Auto-generated constructor stub
        holder = getHolder();

    }

    // float aX, aY;

    @Override
    public void run() {
        // TODO Auto-generated method stub
        while (isitok == true) {
            // perform drawing
            if (!holder.getSurface().isValid()) {
                continue;
            }
            Canvas canvas = holder.lockCanvas();
            canvas.drawARGB(255, 150, 150, 10);

            // System.out.println("Canvas matrix  -" + canvas.getm));
            Paint p = new Paint();

            // canvas.drawBitmap(tball, (x - tball.getWidth()) / 2,
            // (y - tball.getHeight()) / 2, p);
            p.setStyle(Paint.Style.STROKE);
            p.setColor(Color.WHITE);
            p.setColor(Color.parseColor("#0101DF"));

            canvas.drawCircle(canvas.getWidth() / 2,
                    canvas.getHeight() / 2, 110, p);
            canvas.drawCircle(canvas.getWidth() / 2,
                    canvas.getHeight() / 2, 210, p);

            float x = (canvas.getWidth() / 2) - (tball.getWidth() / 2);
            float y = (canvas.getHeight() / 2) - 210 + (210 - 110) / 2
                    - (tball.getHeight() / 2);
            float MX = canvas.getWidth() / 2;
            float MY = canvas.getHeight() / 2;

            for (double i = 0; i < 12 ; i++) {
                float R = 160;
                x = (float) (MX + (R * Math.cos(i)));
                y = (float) (MY + (R * Math.sin(i)));
                //y = (float) (MY - (R * Math.sin( i )));
                canvas.drawBitmap(tball, x, y, p);

                i++;
            }

            // float movingpts[];

            holder.unlockCanvasAndPost(canvas);
        }
    }

    public void pause() {
        isitok = false;
        while (true) {
            try {
                t.join();
            } catch (InterruptedException e) {
                // TODO: handle exception
                e.printStackTrace();
            }
            break;
        }
        t = null;
    }

    public void resume() {
        isitok = true;
        t = new Thread(this);
        t.start();

    }

}

}"
公共类MainActivity扩展活动{
我们的观点五;
位图tball;
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
v=新的ourView(本);
setContentView(v);
tball=(BitmapFactory.decodeResource(getResources()),
R.可牵引蓝球);
}
受保护的void onPause(){
super.onPause();
v、 暂停();
}
受保护的void onResume(){
super.onResume();
v、 恢复();
}
公共类ourView扩展了SurfaceView实现Runnable{
螺纹t;
表面焊钳;
布尔值isitok=false;
公共视图(上下文){
超级(上下文);
//TODO自动生成的构造函数存根
holder=getHolder();
}
//浮斧,唉;
@凌驾
公开募捐{
//TODO自动生成的方法存根
while(isitok==true){
//作画
如果(!holder.getSurface().isValid()){
继续;
}
Canvas Canvas=holder.lockCanvas();
画布.drawARGB(255、150、150、10);
//System.out.println(“画布矩阵-”+Canvas.getm));
油漆p=新油漆();
//canvas.drawBitmap(tball,(x-tball.getWidth())/2,
//(y-tball.getHeight())/2,p);
p、 设置样式(油漆、样式、笔划);
p、 setColor(Color.WHITE);
p、 setColor(Color.parseColor(#0101DF));
canvas.drawCircle(canvas.getWidth()/2,
getHeight()/21110,p);
canvas.drawCircle(canvas.getWidth()/2,
getHeight()/2210,p);
float x=(canvas.getWidth()/2)-(tball.getWidth()/2);
float y=(canvas.getHeight()/2)-210+(210-110)/2
-(tball.getHeight()/2);
float MX=canvas.getWidth()/2;
float MY=canvas.getHeight()/2;
对于(双i=0;i<12;i++){
浮点数R=160;
x=(浮点)(MX+(R*Math.cos(i));
y=(float)(MY+(R*Math.sin(i));
//y=(float)(MY-(R*Math.sin(i));
画布.绘图位图(tball,x,y,p);
i++;
}
//浮动移动点[];
支架。解锁画布和立柱(画布);
}
}
公共空间暂停(){
isitok=假;
while(true){
试一试{
t、 join();
}捕捉(中断异常e){
//TODO:处理异常
e、 printStackTrace();
}
打破
}
t=零;
}
公众简历(){
isitok=真;
t=新螺纹(本螺纹);
t、 start();
}
}
}"
`

看一看。这是一个动画库,适用于所有1.0版的android版本。我不知道是否有可能实现固定循环路径动画,但该库似乎非常强大

以下是路径动画的示例代码:

请阅读。什么不起作用?错误是什么?请提供更多信息,并尝试提出特定问题,否则您不太可能获得帮助。