Add sample code for specifying per-keyframe interpolator in xml

Depend on ag/667176
Bug: 19913234

Change-Id: Iaf4160646a972dcc9fd1d885f1ffc0cd68a3b6ac
This commit is contained in:
Doris Liu
2015-04-02 16:25:05 -07:00
parent edcf97efa7
commit 2ef936dbae
3 changed files with 53 additions and 4 deletions

View File

@@ -18,7 +18,6 @@
android:duration="1000"
android:repeatCount="1"
android:repeatMode="reverse">
<!-- BEGIN_INCLUDE(KeyframeResources) -->
<propertyValuesHolder android:propertyName="x" >
<keyframe android:fraction="0" android:value="800" />
<keyframe android:fraction=".2" android:value="1000" />
@@ -26,8 +25,7 @@
</propertyValuesHolder>
<propertyValuesHolder android:propertyName="y" >
<keyframe/>
<keyframe android:value="300" />
<keyframe android:fraction=".2" android:value="300" />
<keyframe android:value="1000" />
</propertyValuesHolder>
<!-- END_INCLUDE(KeyframeResources) -->
</objectAnimator>

View File

@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2015 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="1000"
android:repeatCount="1"
android:repeatMode="reverse">
<!-- BEGIN_INCLUDE(KeyframeResources) -->
<propertyValuesHolder android:propertyName="x" >
<keyframe android:fraction="0" android:value="800" />
<keyframe android:fraction=".2"
android:interpolator="@android:anim/accelerate_interpolator"
android:value="1000" />
<keyframe android:fraction="1"
android:interpolator="@android:anim/accelerate_interpolator"
android:value="400" />
</propertyValuesHolder>
<propertyValuesHolder android:propertyName="y" >
<keyframe/>
<keyframe android:fraction=".2"
android:interpolator="@android:anim/accelerate_interpolator"
android:value="300"/>
<keyframe android:interpolator="@android:anim/accelerate_interpolator"
android:value="1000" />
</propertyValuesHolder>
<!-- END_INCLUDE(KeyframeResources) -->
</objectAnimator>

View File

@@ -81,6 +81,7 @@ public class AnimationLoading extends Activity {
addBall(650, 50);
addBall(800, 50);
addBall(950, 50);
addBall(800, 50, Color.YELLOW);
}
private void createAnimation() {
@@ -126,9 +127,19 @@ public class AnimationLoading extends Activity {
}
});
// This animation has an accelerate interpolator applied on each
// keyframe interval. In comparison, the animation defined in
// R.anim.object_animator_pvh_kf uses the default linear interpolator
// throughout the animation. As these two animations use the
// exact same path, the effect of the per-keyframe interpolator
// has been made obvious.
ObjectAnimator animPvhKfInterpolated = (ObjectAnimator) AnimatorInflater.
loadAnimator(appContext, R.anim.object_animator_pvh_kf_interpolated);
animPvhKfInterpolated.setTarget(balls.get(7));
animation = new AnimatorSet();
((AnimatorSet) animation).playTogether(anim, fader, seq, colorizer, animPvh,
animPvhKf, faderKf);
animPvhKf, faderKf, animPvhKfInterpolated);
}
}