下面列出了android.animation.ValueAnimator#setObjectValues ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void setCodeSegment(final TextView codeView, String segment) {
ValueAnimator valueAnimator = new ValueAnimator();
valueAnimator.setObjectValues(0, Integer.parseInt(segment));
valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
int value = (int) animation.getAnimatedValue();
codeView.setText(String.format(Locale.getDefault(), "%05d", value));
}
});
valueAnimator.setEvaluator(new TypeEvaluator<Integer>() {
public Integer evaluate(float fraction, Integer startValue, Integer endValue) {
return Math.round(startValue + (endValue - startValue) * fraction);
}
});
valueAnimator.setDuration(1000);
valueAnimator.start();
}
private void startCloudTemplate(String mapTag, long delay, final CircleInfo circleInfo){
ValueAnimator valueAnimator=animMap.get(mapTag);
if (valueAnimator==null){
valueAnimator=ValueAnimator.ofObject(new CircleTypeEvaluator(circleInfo),new CircleInfo(circleInfo.getX(),circleInfo.getY()+circleInfo.getRadius(),0)
,new CircleInfo(circleInfo.getX(),circleInfo.getY(),circleInfo.getRadius()));
valueAnimator.setDuration(600);
valueAnimator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationStart(Animator animation) {
super.onAnimationStart(animation);
circleInfo.setCanDraw(true);
}
});
animMap.put(mapTag,valueAnimator);
}
valueAnimator.setObjectValues(new CircleInfo(circleInfo.getX(),circleInfo.getY()+circleInfo.getRadius(),0)
,new CircleInfo(circleInfo.getX(),circleInfo.getY(),circleInfo.getRadius()));
valueAnimator.setStartDelay(delay);
startValueAnimator(valueAnimator);
}
private ValueAnimator getAnimator(double current, double next, long duration, ValueAnimator.AnimatorUpdateListener updateListener) {
ValueAnimator animator = new ValueAnimator();
animator.setInterpolator(mInterpolator);
animator.setDuration(duration);
animator.setObjectValues(current, next);
animator.setEvaluator(new FloatEvaluator() {
public Integer evaluate(float fraction, float startValue, float endValue) {
return Math.round(startValue + (endValue - startValue) * fraction);
}
});
animator.addUpdateListener(updateListener);
return animator;
}
private void startCountAnimation(TextView textProgress, int duration, int from, int to) {
ValueAnimator animator = new ValueAnimator();
animator.setObjectValues(from, to);
animator.setDuration(duration);
final TextView textView = textProgress;
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
public void onAnimationUpdate(ValueAnimator animation) {
textView.setText("" + (int) animation.getAnimatedValue()+"%");
}
});
animator.start();
}
/**
* Setup the Animator to achieve path morphing.
*
* @param anim The target Animator which will be updated.
* @param arrayAnimator TypedArray for the ValueAnimator.
* @return the PathDataEvaluator.
*/
private static TypeEvaluator setupAnimatorForPath(ValueAnimator anim,
TypedArray arrayAnimator) {
TypeEvaluator evaluator = null;
String fromString = arrayAnimator.getString(R.styleable.Animator_vc_valueFrom);
String toString = arrayAnimator.getString(R.styleable.Animator_vc_valueTo);
PathParser.PathDataNode[] nodesFrom = PathParser.createNodesFromPathData(fromString);
PathParser.PathDataNode[] nodesTo = PathParser.createNodesFromPathData(toString);
if (nodesFrom != null) {
if (nodesTo != null) {
anim.setObjectValues(nodesFrom, nodesTo);
if (!PathParser.canMorph(nodesFrom, nodesTo)) {
throw new InflateException(arrayAnimator.getPositionDescription()
+ " Can't morph from " + fromString + " to " + toString);
}
} else {
anim.setObjectValues((Object) nodesFrom);
}
evaluator = new PathDataEvaluator(PathParser.deepCopyNodes(nodesFrom));
} else if (nodesTo != null) {
anim.setObjectValues((Object) nodesTo);
evaluator = new PathDataEvaluator(PathParser.deepCopyNodes(nodesTo));
}
if (DBG_ANIMATOR_INFLATER && evaluator != null) {
Log.v(LOG_TAG, "create a new PathDataEvaluator here");
}
return evaluator;
}