Android properties that can be animated with ObjectAnimator
Asked Answered
C

5

58

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.

Cornel answered 24/7, 2012 at 14:36 Comment(0)
M
67

Better late than never, so here is the comprehensive list of the properties that can be animated with ObjectAnimator.

http://developer.android.com/guide/topics/graphics/prop-animation.html#views

Magnetics answered 8/2, 2013 at 23:29 Comment(4)
I am curious if that is the complete list? On 9OldAndroid, there is an example that animates the background color of a view, which is not specified in the list. nineoldandroids.com ObjectAnimator.ofInt(this, "backgroundColor", /*Red*/0xFFFF8080, /*Blue*/0xFF8080FF);Lull
The list is not complete, there's at list "xFraction" and "yFraction" that works (saw in DevBytes Sliding Fragments sample)Prut
A complete list won't exist given that it works with anything that has a properly name getter/setter (reflection), or by defining a custom Property. See https://mcmap.net/q/331675/-how-does-android-objectanimator-recognize-the-attributes-setter-methods.Pedro
This list isn't even remotely comprehensive since it can be used on any accessible object with any accessible setter.Beneficence
P
28

The Docs imply that any value can be used with ObjectAnimator as long as you follow a naming convention:

  1. 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 is foo, you need to have a setFoo() 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.
  2. [...]

With respect to your question, View has 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:

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.

Pedro answered 29/6, 2014 at 6:5 Comment(0)
A
27

Here is the comprehensive list of property names that you are looking for:

  • rotation
  • rotationX
  • rotationY
  • translationX
  • translationY
  • scaleX
  • scaleY
  • pivotX
  • pivotY
  • alpha
  • x
  • y

Source: Docs

Aeolotropic answered 10/9, 2017 at 17:18 Comment(0)
F
0

Use "translateX" or "transalteY" to move a <group> Take a look at vectorDrawable

Fume answered 22/2, 2019 at 16:50 Comment(0)
D
0

You can check it at the View.java file in Properties block. Now it starts with the line of:

public static final Property<View, Float> ALPHA = new FloatProperty<View>("alpha")
Deathbed answered 1/11, 2022 at 5:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.