画布上字符串的简单淡出动画,android
我有一个从 View
扩展的自定义视图,其中包含以不同角度绘制的大量文本,并且我希望特定的字符串在首次启动后将其 alpha 值降低到某个水平。任何建议或片段将不胜感激:)
postInvalidateDelayed(...)
似乎不适用于此任务。
I have a custom view extending from View
with lots of text drawn at different angles and I want a particular string to decrease its alpha value to a certain level once, after first start. Any suggestion or snippet would be appreciated :)
postInvalidateDelayed(...)
doesn't seem to work for this task.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
一种可能是在 FrameLayout 内部创建两个相互重叠的视图。一个视图将包含所有静态字符串,另一个视图包含您想要设置动画的字符串。然后向动画视图添加 alpha 动画就很简单了。
对于要附加到动画视图的动画:
在 Activity 的 onCreate(Bundle) 方法中,您可以调用AnimationUtils.loadAnimation(Context, int) 来加载从 xml 资源中获取动画并将其附加到动画视图(前提是您为其提供了 id)。
One possibility might be to create two views, inside of a
FrameLayout
that overlap each other. One view would contain all the static strings, the other the string you want to animate. Then it would be a simple matter of adding an alpha animation to the animated view.And for an animation you would attach to the animated view:
From within your activity's
onCreate(Bundle)
method, you can callAnimationUtils.loadAnimation(Context, int)
to load the animation from the xml resource and attach it to the animated view (provided you give it an id).您可以将
Handler
添加到您的 Activity可以按指定的时间间隔发送消息。当您的活动收到来自处理程序的回调时,它可以通知视图更新您想要更改的部分。示例:
调用
start()
启动处理程序,stop()
停止它。确定何时停止处理程序可能会在handleMessage(Message)
代码中。You can add a
Handler
to your activity that can send messages at a specified interval. When your activity receives a callback from the handler, it can notify the view to update the parts that you want to change.An example:
Calling
start()
starts the handler,stop()
stops it. Determining when to stop the handler will probably be in thehandleMessage(Message)
code.对要褪色的垂直文本边界的正确测量存在错误。这是我的
onDraw
方法There was a mistake in the correct measurement of vertical text bounds to be faded. Here is my
onDraw
method