以编程方式设置Android动画列表
我正在尝试将 gif 动画添加到我的应用程序中。
1-我可以从服务器下载 gif 动画。 2-我能够解码动画 gif(使用我的自定义解码器)并拥有与其帧相对应的单独位图。
现在我想使用逐帧动画来制作它的动画。正如我所读到的,要执行逐帧动画,首先需要的是“动画列表”。
我想知道如何以编程方式创建所需的“动画列表”,其中包含每个位图作为单独的帧。
I am trying to achieve adding the animated gifs into my application.
1- I am able to download the animated gif from server. 2- I am able to decode the animated gif (using my custom decoder) and have a separate Bitmap corresponding to its frames.
Now I want to animate it using the frame by frame animation. As i read, to perform the frame by frame animation the first thing that is required is "animation-list".
I want to know how i can create the required "animation-list" programatically containing each Bitmap as a separate frame.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用类似于 http://androidforums .com/application-development/11620-programmatic-frame-frame-animation-examle-animationdrawable.html 但使用您自己的文件而不是从资源中获取。
请注意,您必须小心下载的屏幕和位图的密度,而不是从资源中获取,否则它在不同的屏幕尺寸/分辨率上可能看起来不同。有关更多信息,请访问:http://developer.android.com/guide/practices/screens_support。 html 特别参见“缩放运行时创建的位图对象”一章
You can use AnimationDrawable similiar to http://androidforums.com/application-development/11620-programmatic-frame-frame-animation-examle-animationdrawable.html but use your own files instead of taken from resources.
Note that you have to be careful about density of screen and bitmaps which are downloaded rather than taken from resources otherwise it might look differently on different screen sizes/resolutions. More about it here: http://developer.android.com/guide/practices/screens_support.html see particularly "Scaling Bitmap Objects created at runtime" chapter
需要注意的是,在 Activity 的 onCreate() 方法期间无法调用对 AnimationDrawable 调用的 start() 方法,因为 AnimationDrawable 尚未完全附加到窗口。如果您想立即播放动画,而不需要交互,那么您可能需要从 Activity 中的 onWindowFocusChanged() 方法调用它,当 Android 将您的窗口置于焦点时,该方法将被调用
It's important to note that the start() method called on the AnimationDrawable cannot be called during the onCreate() method of your Activity, because the AnimationDrawable is not yet fully attached to the window. If you want to play the animation immediately, without requiring interaction, then you might want to call it from the onWindowFocusChanged() method in your Activity, which will get called when Android brings your window into focus