0
サークルアニメーションを作成しようとしていますが、画面自体が更新されず、ムーブを描画するのではなく、さまざまな位置に多くの円が描画されます。私はinvalidate()
メソッドを使用するのではなく、この方法で使用したいのですが、これはリアルタイムアプリケーションに使用したいからです。ここでandroidにアニメーションサークルを描く
はコードです:
public class activity_layout_animation extends SurfaceView implements Runnable {
Thread thread;
boolean CanDraw = false;
Paint red_fill;
int circle_x, circle_y;
Canvas canvas;
SurfaceHolder surfaceHolder;
public activity_layout_animation(Context context){
super(context);
surfaceHolder = getHolder();
circle_x= 130;
circle_y=130;
}
@Override
public void run(){
preparePaint();
while(CanDraw){
if (!surfaceHolder.getSurface().isValid()){
continue;
}
canvas = surfaceHolder.lockCanvas();
motionCircle(10);
canvas.drawCircle(circle_x,circle_y,50, red_fill);
surfaceHolder.unlockCanvasAndPost(canvas);
}
}
public void pause(){
CanDraw = false;
while(true) {
try {
thread.join();
break;
} catch (InterruptedException e) {
e.printStackTrace();
}
}
thread = null;
}
public void resume(){
CanDraw = true;
thread = new Thread(this);
thread.start();
}
private void preparePaint(){
red_fill = new Paint();
red_fill.setColor(Color.RED);
red_fill.setStyle(Paint.Style.FILL);
}
private void motionCircle (int speed){
if ((circle_y == 130) && (circle_x < 650)){
circle_x = circle_x + speed;
}
if ((circle_y < 650) && (circle_x ==650)){
circle_y = circle_y + speed;
}
if ((circle_y == 650) && (circle_x > 130)){
circle_x = circle_x - speed;
}
if ((circle_y > 130) && (circle_x== 130)){
circle_y = circle_y - speed;
}
}
}
はあなたに感謝します!