I am creating a custom ProgressBar that has a bitmap that just rotates. if I use View.invalidate, FPS stutters; deltaTime will increase by 40 or more times. Logic and rendering are almost instantaneous, but calling invalidate makes it slow. So I'm trying SurfaceView, the problem is that I had problems with previously created SurfaceViews with other views, and I would not want to use it. Is there an alternative to SurfaceView and View.invalidate, or am I stuck with them?
EDIT:
To clarify a few more, I create a View , which is an intermediate ProgressBar. So, the view is a ProgressBar. I am also not downloading anything now, I am only trying to get max FPS for my presentation. Some code:
MyProgressBar extends View implements Runnable
And run ()
calculateNewRotation(); invalidate(); post(this);
Where is NewRotation () computed?
long now = SystemClock.uptimeMillis(); int deltaTime = (int) (now - mLastRender); mLastRender = now; mSpinRotation += deltaTime * SPIN_SPEED_PER_MILLISECOND_CLOCKWISE;
The message (this) refers to MyProgressBar, and it will be cyclical for all eternity until I say otherwise.
In my onDraw ()
mCamera.save(); mCamera.rotateZ(mSpinRotation); mCamera.getMatrix(mMatrix); mCamera.restore(); mMatrix.preTranslate(-mTranslatePivotX, -mTranslatePivotY); mMatrix.postTranslate(mTranslatePivotX + mCenterX, mTranslatePivotY + mCenterY); canvas.drawBitmap(mSpinBitmap, mMatrix, mSpinBitmapPaint);
Time to calculate NewRotation () = 1 ms.
Time for onDraw () = 1 ms.
The problem is that the total time often exceeds 40 ms. My solution is then to use SurfaceView, but I don't like the idea of ββhaving a view with a surface drawn with transparent pixels so that the underlying surface is displayed instead. What I'm looking for is the idea that I can get the canvas whenever I want, preferably every 16 ms, to get 60 FPS. So, is there such a view?