Android homescreen widget animations

Viewed 16105

I'm looking into creating a widget that supports animation, ideally via the android.view.animation framework, otherwise by setting properties on the remote views in code triggered from a background service.

Does anyone have any experience with either of these approaches, and is what I'm trying doable, or am I heading up a blind alley?

5 Answers

It's possible, but use it with caution, since it is very heavy to the default homescreen implementation and you shouldn't use it very often.

In the Mario Coin Block widget, I am using such technique to do the animation, you can checkout the source code: http://code.google.com/p/mario-coin-block/source/browse/trunk/MarioWidget.CoinBlock/src/com/gueei/mario/coinBlock/view/CoinBlockView.java

Basically the idea is manually draw on an offscreen Bitmap, and replace the BitmapView's bitmap with it using RemoveViews Call.

I agree with the other answers here, so I won't re-iterate - limited animation on a widget is possible, but heavy on resources, it might make the home screen slow and less responsive, and battery drainer. From my experience - it doesn't run smooth. So the bottom line is - it's ok if it's only few frames changing from time to time, or for some effects seldom upon an event (for example user press or some event from your service.

But here's an idea that probably does not directly answer your question, but may be a suitable alternative (I don't know your use case, it might be not relevant at all) Did you consider implementing a live wallpaper?

pros - highest quality animation, can be controlled from the background

cons - not interactive, replaces the user's wallpaper... and it's hard to satisfy everyone's taste

Related