Android - 以编程方式生成 Textview 或 Drawable 并为其设置动画
首先,我是初学者。如果这远远超出了初学者第一次应用程序的范围,请告诉我。
解释我想要的最好方法是举个例子:在 Robo Defense 中,当你杀死某个东西时,会弹出一点 10 美元,动画会平移/淡出约 5% 的屏幕并消失。 (几乎像吐司一样,出现在画布顶部)
我正在寻找类似于相同效果的东西。就像顶层可绘制对象一样,忽略底层定义的 XML 布局。我可以处理代码的动画部分,但我很好奇如何创建和膨胀该视图而不会对当前布局造成混乱。如果作为可绘制对象而不是文本更容易,那对我的项目来说确实不是一个大问题。它只是提供信息,根本没有交互性,它只是一个 500 毫秒的快速小工件,用于显示已发生操作。
我可以使用正确方向的指针,或者一些类似的代码示例。
First off, I'm a beginner. If this is way beyond the scope of a beginner's first application, just tell me.
The best way to explain what I want is as an example: In Robo Defense, when you kill something, a little $10 pops up, animate translates/fades up about 5% of the screen and disappears. (almost like a toast, appears on top of canvas)
I'm looking for something similar to that same effect. As a like, top-layer drawable that ignores the underlying defined XML layout. I can handle the animation part of the code, but I'm curious as to how to create and inflate that view without wreaking chaos on my current layout. If it would be easier as a drawable instead of text, thats really not a big problem for my project. It is simply imformative, no interactivity at all, it will just be a quick little 500ms artifact to show that an action has occurred.
I could use a pointer in the right direction, or some similar code examples please.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为你会在Java代码中创建TextView,然后使用动画使其升起和消失,一旦动画完成,就销毁TextView。
我以前从未这样做过,但我认为这应该可行!
I think you would create the TextView within your Java code, and then use an animation to make it rise and fade, once the animation has finished, destroy the TextView.
I've never done this before, but I think that should work!
对于其他想知道的人,我最终通过将整个布局包装在RelativeLayout中,进行必要的适当更改,然后使用layout_above以编程方式创建TextView,然后在其上调用Animation来完成此任务。
To anyone else who is wondering, I ended up accomplishing this via wrapping my entire layout in RelativeLayout, making the appropriate changes necessary, then creating a TextView programmatically with layout_above, and then calling an Animation on it.