According to the Android developer site, we can load AnimatorSet
class programatically from xml file located on the path like this: res/animator/filename.xml
. So I have created a sample project and tried to see if it actually works, and it doesn't; nothing happens. It would be very nice if I can understand what is missing and/or what I have done wrong. Thanks in advance! Below is my animator xml file and Java code to load the xml:
res/animator/sample.xml:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:ordering="sequentially"
>
<set>
<objectAnimator
android:propertyName="x"
android:duration="500"
android:valueTo="400"
android:valueType="intType"
/>
<objectAnimator
android:propertyName="y"
android:duration="500"
android:valueTo="300"
android:valueType="intType"
/>
</set>
<objectAnimator
android:propertyName="alpha"
android:duration="500"
android:valueTo="1f"
/>
</set>
And here is my Java codes to load the xml file above:
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View view) {
// Load and start Animaton
AnimatorSet animSet =
(AnimatorSet) AnimatorInflater.loadAnimator(view.getContext(), R.animator.sample);
animSet.setTarget(view);
animSet.start();
}
});