我想在猎物应用程序中创建一个动画背景:
GIF:
我尝试使用自制的Canvas类和android定时器:
画布类:
功能:
public void drawCircle(float x, float y, float radius){
mPath.addCircle(x, y, radius, Path.Direction.CW);
invalidate();
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawPath(mPath, mPaint);
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
mBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
mCanvas = new Canvas(mBitmap);
}
活动类:
final Handler handler = new Handler();
TimerTask timertask = new TimerTask() {
@Override
public void run() {
handler.post(new Runnable() {
public void run() {
runOnUiThread(new Runnable() {
public void run() {
if(size > displayHeight*2 && size > displayWidth*2){
canvasView.clearCanvas();
size = 0;
timer.cancel();
}
canvasView.clearCanvas();
canvasView.drawCircle(0, 0, size, Color.BLACK);
size+=10;
}
});
}
});
}
};
timer = new Timer();
timer.schedule(timertask, 0, 10);
它起作用,但非常不规则并且有帧丢弃 请帮我找一个更好的解决方案!
答案 0 :(得分:0)
@pskink给了我使用ValueAnimator / ObjectAnimator
的提示因此我找到了解决方案:
<强> AnimationSet performance issue 强>
和
https://developer.android.com/training/basics/fragments/creating.html https://developer.android.com/samples/GridViewPager/res/drawable/shape.html