Efficient 2D drawing in Android

后端 未结 2 713
伪装坚强ぢ
伪装坚强ぢ 2021-02-01 11:01

I have searched for quite a few hours and have not been able to find a concise definite andswer to my question. I have an application where I need to draw a sports field (includ

相关标签:
2条回答
  • 2021-02-01 11:37

    Is your sports field static or does is scroll over the screen? If it is static, you should consider to build it once and save it as an image which than will be redrawn each time. Another thing: The emulator is very slow in comparison with modern devices. You should check your performance at least on a G1 or later to verify the real performance.

    0 讨论(0)
  • 2021-02-01 11:40

    You should definitely be caching any canvas drawing which will not change to a bitmap at initialization time and then draw that bitmap in onDraw(). That will help render times a lot. Something like:

    Bitmap mField = null;
    
    void init()
    {
      mField = new Bitmap(...dimensions...);
      Canvas c = new Canvas(mField);
      c.drawRect(...);
      ...
    }
    
    void onDraw(Canvas c)
    {
      c.drawBitmap(mField);
    }
    
    0 讨论(0)
提交回复
热议问题