当使用SurfaceView时,我得到大约6 FPS,当时我几乎什么都没画。
我只画一种颜色。所以几乎没有绘图操作,我得到6 fps,这是非常可怕的。
然而有一点需要注意的是,我正在使用模拟器(genymotion模拟器)并且没有在真实设备上尝试过。然而,即使有一个模拟器,当我什么都没画时,我应该超过6 fps ..
所以这是我的代码(不包括import语句):
//Activity class which starts the SurfaceView
public class MainActivity extends Activity {
SView surfaceView;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
surfaceView = new SView(this);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(surfaceView);
}
}
//SurfaceView class which draws everything in another thread
class SView extends SurfaceView implements SurfaceHolder.Callback{
SurfaceHolder holder;
Canvas mainCanvas;
Paint mainPaint;
int width;
long start, end, fps;
public SView(Context context) {
super(context);
holder = getHolder();
holder.addCallback(this);
mainPaint = new Paint();
mainPaint.setColor(Color.BLACK);
fps = 0;
}
public void surfaceCreated(SurfaceHolder holder) {
new Thread(){
public void run() {
start = System.currentTimeMillis();
while (true) {
end = System.currentTimeMillis();
if ((end - start) >= 1000) {
Log.d("PERSONAL", "FPS: " + fps + " milliseconds " + Long.toString(end - start));
start = System.currentTimeMillis();
fps = 0;
}
customDraw();
}
}
}.start();
}
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
}
public void surfaceDestroyed(SurfaceHolder holder) {
}
public void customDraw(){
mainCanvas = holder.lockCanvas();
mainCanvas.drawRGB(0,150,0);
fps++;
holder.unlockCanvasAndPost(mainCanvas);
}
}
所以我的问题是如何解决这个可怕的fps这个问题?