My problem is probably really simple. I recently picked up creating live wallpapers for Android (and Android coding in general), and I lack the basics behind Live Wallpaper coding, since it's really hard to find.
I would like to create a Live Wallpaper with 2 (or more) "layers". My two so called layers are:
- background which reacts to touch events
- a bitmap, which is on top
At the moment I'm drawing everything in a single Canvas, which looks like this:
Resources res = getResources();
Bitmap image = BitmapFactory.decodeResource(res, R.drawable.image);
Canvas c = null;
try {
c = holder.lockCanvas();
if (c != null) {
c.drawARGB(aa, rr, gg, bb);
c.drawBitmap(image, 0, 0, paint);
}
} finally {
if (c != null) holder.unlockCanvasAndPost(c);
}
It works, but the performance is really bad, since I'm drawing this relatively large PNG file on each frame redraw.
I would like to know what is the best way to display bitmaps in Live Wallpapers?
As well as how to later animate them (basically just change the position for a start) without having to redraw them each time?
Finally, how to determine the z-index (have multiple layers) in Live Wallpapers - can this also be done with XML like in "normal apps"?