我从 Android Wear 开始,我想做一个圆形动画,让成长。我知道该怎么做,我想,但它做起来非常非常慢,希望你能帮助我
我有这个类变量
Paint mAnimation;
在方法 OnCreate 上初始化
mAnimation = new Paint(Paint.ANTI_ALIAS_FLAG);
mAnimation.setStyle(Paint.Style.FILL);
mAnimation.setColor(Color.GREEN);
在 OnDraw 方法上我有
@Override
public void onDraw(Canvas canvas, Rect bounds) {
int width = bounds.width();
int height = bounds.height();
float centerX = width / 2f;
float centerY = height / 2f;
// Draw the background.
canvas.drawRect(0, 0, bounds.width(), bounds.height(), mBackgroundPaint);
canvas.drawCircle(0, centerY, radiusPlus, mAnimation);
radiusPlus += 20;
}
动画是“正确的”,但很慢,就像暂停一样。
谢谢!!
编辑
我找到了一个例子,现在我终于找到了原因。我没有在 OnDraw 结束时使视图无效。现在它工作正常。谢谢。
@Override
public void onDraw(Canvas canvas, Rect bounds) {
int width = bounds.width();
int height = bounds.height();
float centerX = width / 2f;
float centerY = height / 2f;
// Draw the background.
canvas.drawRect(0, 0, bounds.width(), bounds.height(), mBackgroundPaint);
canvas.drawCircle(0, centerY, radiusPlus, mAnimation);
radiusPlus += 5;
if (isVisible() && !isInAmbientMode()) {
invalidate();
}
}