Alternative to SurfaceView?

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?

+4
source share
2 answers

What I did at the end was when I drew the image, I update the rotation value to 1. On fast and slow phones it will look smooth, but the speed will be different. On a fast phone, it can dial 60 frames per second, which is 60 degrees per second, when a slow phone with 10 frames per second will cause the rotation to go 10 degrees per second. Therefore, in the end, the whole point is whether I want them to rotate at the same speed or to do it well, I choose the latter.

EDIT

I suppose I can set the maximum frames per second, so that the fast phones will be throttled and thus the gap between the fast and small phones will be reduced.

0
source

Do you perform a lengthy operation (usually the cause of the progress bar) in the user interface thread? Your UI thread should update the progress bar while another thread or async task is processing a lengthy operation.

+1
source

Source: https://habr.com/ru/post/1445988/


All Articles