Just thought I'd share a little tip when drawing onto a view using the .invalidate() function with you lovely people. All tutorials on here which I've seen so far all use MyView.invalidate();, which if your view is fullscreen is one cpu whore.
Its always better when drawing, especially on mobile devices with lower cpu's, to only ever draw exactly what you need. To do this we pass a Rect as the parameter to invalidate().
Example:
Using java Syntax Highlighting
- public class MyActivity extends Activity
- {
- Handler loopTheLoop = new Handler()
- {
- public void handleMessage()
- {
- int x = 0;
- int y = 100;
- int width = 0;
- int height = 100;
- Rect invalidRect = new Rect(x, y, width, height);
- view.invalidate(invalidRect);
- }
- }
- }
Parsed in 0.031 seconds, using GeSHi 1.0.8.4
This will only redraw the specified area defined by Rect instead of the whole screen meaning less pressure on the cpu/gpu. Which is especially useful for any fullscreen or smooth animation.
Hope it helps someone


