(Android)
I am working on adapting a full-screen analog clock app to a live wallpaper.
The app use three separate ImageView
for hour, min, sec hands and RotateAnimation
.
I have been looking around for a method to use ImageView in live wallpaper. this and this indicates that this should be possible with measure()
and layout()
, but I
don't really know how to use it.
For example, I use the code below to load clock_background.png
into a ImageView
.
public class MyWallpaperService extends WallpaperService {
@Override
public Engine onCreateEngine() {
return new MyWallpaperEngine();
}
....
public void onCreate(SurfaceHolder surfaceHolder) {
super.onCreate(surfaceHolder);
mContext = getBaseContext();
backgroundImage = new ImageView(mContext);
backgroundImage.setImageDrawable(mContext.getResources().getDrawable(R.drawable.clock_background));
}
}
Later I have:
backgroundImage.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
backgroundImage.layout(0, 0, 150, 150);
I expect the code above would display clock_background.png
in the upper-left corner of
the screen. I tried to put the two lines above in OnSurfaceCreated
and OnSurfaceChanged
. Unfortunately it does not work.
As I understand, live wallpaper gives a Surface (not SurfaceView), from which one can get
canvas and draw things on it.
I apologise for being very new at Android: Am I doing it all wrong? I just don't want to
mess with drawBitmap
or likes, and I don't care about battery anyway.
Any help is highly appreciated. Thank you very much!