可以使用 ObjectAnimator 进行动画处理的 Android 属性
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11633221/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Android properties that can be animated with ObjectAnimator
提问by Cathal Comerford
I am starting to play around with Property Animations over view animations as I have a view that needs to scale and push others out of the way as it does. I've seen some examples but I'm just wondering if there is anywhere that provides a list of the properties that can be altered using these classes. For example, I saw one tutorial that did a quick rotation using:
我开始在视图动画上使用属性动画,因为我有一个视图需要缩放并将其他视图推开。我看过一些例子,但我只是想知道是否有任何地方提供可以使用这些类更改的属性列表。例如,我看到一个使用以下方法进行快速旋转的教程:
ObjectAnimator.ofFloat(aniView, "rotation", 360)
Which is quite cool, but I wouldn't have known the rotation property if not for that exact tutorial, is there any comprehensive list of what can be done? The particular property I want to animate is the weight of a view within a LinearLayout, if anyone has any advice on that specifically.
这很酷,但如果不是那个确切的教程,我不会知道旋转属性,有什么可以做的综合列表吗?我想要动画的特定属性是 LinearLayout 中视图的权重,如果有人对此有任何建议的话。
回答by Onyx
Better late than never, so here is the comprehensive list of the properties that can be animated with ObjectAnimator.
迟到总比不到好,所以这里是可以使用 ObjectAnimator 进行动画处理的完整属性列表。
http://developer.android.com/guide/topics/graphics/prop-animation.html#views
http://developer.android.com/guide/topics/graphics/prop-animation.html#views
回答by bcorso
The Docsimply that any value can be used with ObjectAnimatoras long as you follow a naming convention:
该文件意味着任何价值可与使用ObjectAnimator,只要你遵循命名约定:
- The object property that you are animating must have a setter function (in camel case) in the form of
set<propertyName>(). Because the ObjectAnimator automatically updates the property during animation, it must be able to access the property with this setter method. For example, if the property name isfoo, you need to have asetFoo()method. If this setter method does not exist, you have three options:
- Add the setter method to the class if you have the rights to do so.
- Use a wrapper class that you have rights to change and have that wrapper receive the value with a valid setter method and forward it to the original object.
- Use ValueAnimator instead.
- [...]
- 您正在设置动画的对象属性必须具有形式为
set<propertyName>(). 因为 ObjectAnimator 在动画过程中会自动更新属性,所以它必须能够使用这个 setter 方法访问该属性。例如,如果属性名称是foo,则需要有一个setFoo()方法。如果这个 setter 方法不存在,你有三个选择:
- 如果您有权将 setter 方法添加到类中。
- 使用您有权更改的包装器类,并让该包装器使用有效的 setter 方法接收值并将其转发给原始对象。
- 请改用 ValueAnimator。
- [...]
With respect to your question, Viewhas the method setRotation(float)-- that gives you a hint it can be used. In particular here's how you would do it with a particular TimeInterpolator:
关于您的问题,View有方法setRotation(float)- 为您提供可以使用的提示。特别是这里是你如何使用特定的TimeInterpolator:
ObjectAnimator anim = ObjectAnimator.ofFloat(myView, "rotation", 0f, 90f);
anim.setDuration(2000); // Duration in milliseconds
anim.setInterpolator(timeInterpolator); // E.g. Linear, Accelerate, Decelerate
anim.start() // Begin the animation
You can read the docs for more details on the expectations of ObjectAnimator.
您可以阅读文档以了解有关ObjectAnimator.
回答by Sagar
回答by Milk Littile
Use "translateX" or "transalteY" to move a <group>Take a look at vectorDrawable
使用“ translateX”或“ transalteY”来移动<group>一个看看vectorDrawable

