0

I'm creating a custom TextView by using TextPaint in the onDraw() method. however this is causing severe problems for my app. performance wise I mean.

The onDraw() method gets called over and over again . but i just want it to draw once :(

i tried using setDrawingCacheEnabled(true); but no effect there.

There is also a viewflipper with textviews in the main layout rotating automaticly, could this be causing everything to redraw ?

can anyone give me some pointers here ?

ron
  • 159
  • 2
  • 11

1 Answers1

0

As well as enabling the drawing cache, try creating a new bitmap instance in the inDraw and pass that to the Canvas to draw to. In the next call to onDraw, simply draw that bitmap if it is not null. I'm doing this myself and it works a charm to improve performance, though unable to copy the code right now (out using phone).

As for why it is being consistently redrawn, are there any moving overlapping graphics causing it to be invalidated?

Trevor
  • 10,903
  • 5
  • 61
  • 84
  • how would i apply that ? it's a class extending TextView in the onDraw i just set the TextView settings as of yet. setTextsize e.g. – ron Jun 30 '11 at 08:31
  • Take a look at the onDraw code in the answer I posted to my own question here: – Trevor Jun 30 '11 at 08:55
  • Take a look at the onDraw code in the answer I posted to my own question here: http://stackoverflow.com/questions/6378904/extending-relativelayout-and-overriding-dispatchdraw-to-create-a-zoomable-view – Trevor Jun 30 '11 at 08:55