如何以编程方式为自定义视图 (ImageView) 制作动画?
我想以编程方式为自定义视图设置动画。我希望它只在 xml 文件中声明的位置进行动画处理,并且我不希望它弄乱布局。而且这个动画还受到其他因素的影响,所以 android Animation 类是不可能的。
我已经测试了这个示例教程并观看这个视频。我的问题是,大多数教程都是为了将精灵动画化到画布中,您将在其中追踪精灵的位置。
如何在不影响布局且不使用 Android Animation 类的情况下为自定义视图设置动画?
编辑: 自定义视图将充当动画 gif,并在事件激活它时切换另一组帧。
I want to animate a custom view programmatically. I want it to only animate in the position where it is declare in the xml file, and I don't want it to mess the layout. Also this animation is affected by other factor so the android Animation class is out of the question.
I have test this sample tutorial and watch this videos. My problem is that most tutorial is for animating a sprite into a canvas where you will trace your sprite's location.
How can you animate the custom view without affecting layout and without using the Android Animation class?
Edited:
The custom view will act as a animated-gif and will toggle another set of frames whenever an event activates it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以创建动画 XML 并将该动画从程序应用到 ImageView 检查以下示例,
您可以为自定义视图启动动画,只需调用
viewobject.startAnimation(animationobject);
animation.xml
你的 main.xml
然后你的活动类 myActivity.java
you can create animation XML and apply that animation from program to your ImageView check following example
you can start animation for your customized view just call
viewobject.startAnimation(animationobject);
animation.xml
your main.xml
then your activity class myActivity.java
如果您想要“逐帧”动画,就像动画 gif 一样“运行”,您可以按照以下步骤操作:
drawable-animation 官方教程。
引用教程:
并在您的代码中
If you want "frame by frame" animation that just "runs" like an animated gif, you can follow:
drawable-animation official tutorial.
Quoting from the tutorial:
and in your code