I have the following definition for an animation in res/animator/grow.xml:
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:ordering="sequentially">
<set>
<objectAnimator
android:propertyName="scaleX"
android:duration="150"
android:valueFrom="1.0"
android:valueTo="1.5"
android:valueType="floatType" />
<objectAnimator
android:propertyName="scaleY"
android:duration="150"
android:valueFrom="1.0"
android:valueTo="1.5"
android:valueType="floatType" />
</set>
</set>
What I want is for the pivotX and pivotY to be in the center of the object, rather than the upper left hand corner. I know I could accomplish this via code, but I'd rather not do that. Instead, I'd like to specify it in the XML file. I thought about doing this:
<objectAnimator
android:propertyName="pivotX"
android:valueTo="50%" />
<objectAnimator
android:propertyName="pivotY"
android:valueTo="50%" />
But, this seems like it's going to try and animate that property as well, which is not what I want. Instead, I want it to set the pivots and then perform the animation. Can I do this in XML, and if so, how?
Old question without an answer and I didnt find an answer anywhere else, so I'll post my solution here:
Logic:
duration=0
durations
to all other animationsstartOffset
and duration=0
Optinally, don't use durations and don't reset the pivot... In this case, the pivot will just stay as it is, which in most cases is irrelevant.
Code
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<set>
<objectAnimator
android:duration="0"
android:propertyName="pivotX"
android:valueTo="0" />
<objectAnimator
android:duration="@android:integer/config_shortAnimTime"
android:propertyName="scaleX"
android:valueTo="0.85" />
<objectAnimator
android:duration="@android:integer/config_shortAnimTime"
android:propertyName="scaleY"
android:valueTo="0.85" />
</set>
</item>
<item android:state_pressed="false">
<set>
<objectAnimator
android:duration="@android:integer/config_shortAnimTime"
android:propertyName="scaleX"
android:valueTo="1.0" />
<objectAnimator
android:duration="@android:integer/config_shortAnimTime"
android:propertyName="scaleY"
android:valueTo="1.0" />
<objectAnimator
android:duration="0"
android:propertyName="pivotX"
android:startOffset="@android:integer/config_shortAnimTime"
android:valueTo="0" />
</set>
</item>
</selector>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With