Animation.setFillAfter/Before - 它们有效吗/它们有什么用? [英] Animation.setFillAfter/Before - Do they work/What are they for?

查看:31
本文介绍了Animation.setFillAfter/Before - 它们有效吗/它们有什么用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如我的问题的标题,setFillBefore()setFillAfter() 方法应该做什么?

As in the title of my question what are the methods setFillBefore() and setFillAfter() supposed to do?

我希望 setFillAfter() 能够在动画完成后永久更改视图,但这是不正确的吗?

I was hoping setFillAfter() would make the change to the View permanent after an animation has completed, but this is incorrect?

推荐答案

答案是肯定的,它们确实有效,只是可能不符合您的预期 - 例如,对 setFillAfter(boolean fillAfter) 的描述代码>说

The answer is yes, they do work, just probably not for what you expect - for instance, the description for setFillAfter(boolean fillAfter) says

如果fillAfter为真,则这个动画的转换执行时将持续存在完成.

If fillAfter is true, the transformation that this animation performed will persist when it is finished.

当设置为 true 时,它​​会这样做.

and when set to true it does do this.

然而,不直观的是,Android 上的动画实际上并没有对 View 本身进行动画处理,而是对 View 的位图表示进行了动画处理.

However, unintuitively an animation on Android does not actually animate the View itself, rather it animates a bitmap representation of the View.

您可能遇到的问题是,在动画播放后,视图会恢复到动画播放前的状态 - setFillAftersetFillBefore 无法帮助您解决这个问题,因为在那种情况下,您真正​​想要做的是将 View 的属性设置为与动画表示相同(它们是单独的东西),并且仅 setFillAftersetFillBefore应用于动画属性,而不是视图属性.

The issue you are probably having is that after an animation the View goes back to being how it was before the animation - setFillAfter and setFillBefore cannot help you with that, because in that situation what you really want to do is set the properties of the View to be same as the animated representation (they are separate things), and setFillAfter and setFillBefore only apply to animation properties, not View properties.

它们存在的原因是为了链接动画.假设您有一个翻译动画,然后是淡出.如果你没有在平移动画上设置 setFillAfter(true),那么 View 会平移,跳回它的原始位置,然后淡出.在平移动画上设置 setFillAfter(true) 后,视图将移动,然后在当前位置淡出.

The reason they exist is for chaining animations. Suppose you had a translate animation followed by a fade out. If you did not set setFillAfter(true) on the translate animation, then the View would translate, jump back to it's original position and then fade out. With setFillAfter(true) set on the translate animation, the view will move and then fade out at it's current spot.

这篇关于Animation.setFillAfter/Before - 它们有效吗/它们有什么用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆