'Android - Animate startX propery of gradient color in xml
I have an animated-vector that has gradient as its stripeColor.
I would like to animate the startX property of the gradient, created color_to_animate to do this, but this doesn't seem to work, am I missing something here?
Note animating other properties, e.g the strokeWidth of border_path works fine
<animated-vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt">
<aapt:attr name="android:drawable">
<vector
android:name="vector"
android:width="180dp"
android:height="120dp"
android:viewportWidth="300"
android:viewportHeight="200">
<path
android:name="border_path"
android:pathData="
M 2.5,20
L 2.5,7.5
a 5,5,0,0,1,5,-5
L 292.5,2.5
a 5,5,0,0,1,5,5
L 297.5,192.5
a 5,5,0,0,1,-5,5
L 7.5,197.5
a 5,5,0,0,1,-5,-5
Z"
android:strokeWidth="5">
<aapt:attr name="android:strokeColor">
<gradient
android:name="color_to_animate"
android:startColor="@color/viewfinder_border_center"
android:endColor="#FFFFFF"
android:startX="0"
android:endX="300"
android:startY="0"
android:endY="200"
android:type="linear" />
</aapt:attr>
</path>
</vector>
</aapt:attr>
<target android:name="color_to_animate">
<aapt:attr name="android:animation">
<objectAnimator
android:propertyName="startX"
android:duration="1500"
android:valueFrom="0"
android:valueTo="300"
android:valueType="intType"
android:interpolator="@android:interpolator/linear" />
</aapt:attr>
</target>
</animated-vector>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
