Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
335 views
in Technique[技术] by (71.8m points)

android - Is there a way to animate on a Home Widget?

I want to use an animation on a Home page Widget, i.e. an AppWidgetProvider. I was hoping to use the "Frame Animation" technique:

http://developer.android.com/guide/topics/graphics/2d-graphics.html#frame-animation

which I've used successfully in an activity. But I can't translate that code to an AppWidgetProvider.

Basically, in an AppWidgetProvider, I create and work with a RemoteViews object, which AFAIK doesn't provide me with a method to get a reference to an ImageView in the layout for me to call start() on the animation. There is also not a handler or a callback for when the widget displays so I can make the start() call.

Is there another way this can be done? I suppose that I can probably do the animation on my own with very fast onUpdate() calls on the widget, but that seems awfully expensive.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Do not animate app widgets, unless you write you own home screen app.

You are correct that you have no way to manipulate an AnimationDrawable or an Animation to have them work with an app widget.

You are also correct that "very fast onUpdate() calls on the widget...seems awfully expensive", because it is. Updates to app widgets involve inter-process communication, between your AppWidgetProvider and the process hosting the home screen. This system is designed for updates every 30 minutes or so, not 30 frames per second.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...