下面列出了android.animation.ValueAnimator#getAnimatedFraction ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
if (valueAnimator.getCurrentPlayTime() <= valueAnimator.getDuration()) {
float fraction = valueAnimator.getAnimatedFraction();// 动画进度
float scaleXDuration = mFinalBounds.width() - mStartBounds.width();
float scaleYDuration = mFinalBounds.height() - mStartBounds.height();
mView.getLayoutParams().width = (int)(mStartBounds.width() + (scaleXDuration * fraction));
mView.getLayoutParams().height = (int)(mStartBounds.height() + (scaleYDuration * fraction));
if (mListener != null) {
mListener.onViewAnimationUpdate(mView, valueAnimator, fraction);
}
}
mView.requestLayout();
}
@Override
public void onAnimationUpdate(ValueAnimator animation) {
if (DEBUG) {
log("Animation update "
+ animation.getAnimatedFraction() + " on: "
+ Thread.currentThread().getName());
}
mBackgroundFraction = animation.getAnimatedFraction();
// propagate the animation event to all listeners
for (ValueAnimator.AnimatorUpdateListener listener : mAnimationListenerCache) {
listener.onAnimationUpdate(animation);
}
// animation updates occur on the main thread. it is save to call invalidate here.
PieLayout.this.invalidate();
}
@Override
public void onAnimationUpdate(ValueAnimator animation) {
if (view.getLayoutParams() != null) {
ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
TimeInterpolator interpolator = animation.getInterpolator();
float fraction = animation.getAnimatedFraction();
int preWidth = layoutParams.width;
int preHeight = layoutParams.height;
if (width != null) {
layoutParams.width = intEvaluator.evaluate(interpolator.getInterpolation(fraction),
width.first,
width.second);
}
if (height != null) {
layoutParams.height = intEvaluator.evaluate(interpolator.getInterpolation(fraction),
height.first,
height.second);
}
if (preHeight != layoutParams.height || preWidth != layoutParams.width) {
view.requestLayout();
}
}
}
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
if (hasView()) {
float animatedFraction = valueAnimator.getAnimatedFraction();
if (mLeftMargin != null) {
mParams.leftMargin = (int) calculateAnimatedValue(mLeftMargin.mFrom, mLeftMargin.mTo, animatedFraction);
}
if (mTopMargin != null) {
mParams.topMargin = (int) calculateAnimatedValue(mTopMargin.mFrom, mTopMargin.mTo, animatedFraction);
}
if (mRightMargin != null) {
mParams.rightMargin = (int) calculateAnimatedValue(mRightMargin.mFrom, mRightMargin.mTo, animatedFraction);
}
if (mBottomMargin != null) {
mParams.bottomMargin = (int) calculateAnimatedValue(mBottomMargin.mFrom, mBottomMargin.mTo, animatedFraction);
}
mView.get().requestLayout();
}
}
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
if (hasView()) {
float animatedFraction = valueAnimator.getAnimatedFraction();
int leftPadding = currentLeftPadding();
int topPadding = currentTopPadding();
int rightPadding = currentRightPadding();
int bottomPadding = currentBottomPadding();
if (mLeftPadding != null) {
leftPadding = (int) calculateAnimatedValue(mLeftPadding.mFrom, mLeftPadding.mTo, animatedFraction);
}
if (mTopPadding != null) {
topPadding = (int) calculateAnimatedValue(mTopPadding.mFrom, mTopPadding.mTo, animatedFraction);
}
if (mRightPadding != null) {
rightPadding = (int) calculateAnimatedValue(mRightPadding.mFrom, mRightPadding.mTo, animatedFraction);
}
if (mBottomPadding != null) {
bottomPadding = (int) calculateAnimatedValue(mBottomPadding.mFrom, mBottomPadding.mTo, animatedFraction);
}
mView.get().setPadding(leftPadding, topPadding, rightPadding, bottomPadding);
}
}
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
if (valueAnimator.getCurrentPlayTime() <= valueAnimator.getDuration()) {
float fraction = valueAnimator.getAnimatedFraction();// 动画进度
float scaleXDuration = mFinalBounds.width() - mStartBounds.width();
float scaleYDuration = mFinalBounds.height() - mStartBounds.height();
mView.getLayoutParams().width = (int)(mStartBounds.width() + (scaleXDuration * fraction));
mView.getLayoutParams().height = (int)(mStartBounds.height() + (scaleYDuration * fraction));
if (mListener != null) {
mListener.onViewAnimationUpdate(mView, valueAnimator, fraction);
}
}
mView.requestLayout();
}
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
float fraction = valueAnimator.getAnimatedFraction();
double lat = (to.latitude - from.latitude) * fraction + from.latitude;
double lngDelta = to.longitude - from.longitude;
// Take the shortest path across the 180th meridian.
if (Math.abs(lngDelta) > 180) {
lngDelta -= Math.signum(lngDelta) * 360;
}
double lng = lngDelta * fraction + from.longitude;
LatLng position = new LatLng(lat, lng);
marker.setPosition(position);
}
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
if (hasView()) {
float animatedFraction = valueAnimator.getAnimatedFraction();
if (mWidthPercent != null) {
mPercentLayoutInfo.widthPercent = calculateAnimatedValue(mWidthPercent.mFrom, mWidthPercent.mTo, animatedFraction);
}
if (mHeightPercent != null) {
mPercentLayoutInfo.heightPercent = calculateAnimatedValue(mHeightPercent.mFrom, mHeightPercent.mTo, animatedFraction);
}
if (mLeftMarginPercent != null) {
mPercentLayoutInfo.leftMarginPercent = calculateAnimatedValue(mLeftMarginPercent.mFrom, mLeftMarginPercent.mTo, animatedFraction);
}
if (mTopMarginPercent != null) {
mPercentLayoutInfo.topMarginPercent = calculateAnimatedValue(mTopMarginPercent.mFrom, mTopMarginPercent.mTo, animatedFraction);
}
if (mRightMarginPercent != null) {
mPercentLayoutInfo.rightMarginPercent = calculateAnimatedValue(mRightMarginPercent.mFrom, mRightMarginPercent.mTo, animatedFraction);
}
if (mBottomMarginPercent != null) {
mPercentLayoutInfo.bottomMarginPercent = calculateAnimatedValue(mBottomMarginPercent.mFrom, mBottomMarginPercent.mTo, animatedFraction);
}
if (mAspectRatio != null) {
mPercentLayoutInfo.aspectRatio = calculateAnimatedValue(mAspectRatio.mFrom, mAspectRatio.mTo, animatedFraction);
}
mView.get().requestLayout();
}
}
@Override
public void onAnimationUpdate(ValueAnimator animation) {
float t = animation.getAnimatedFraction();
if (t > mAnimationTimeFraction) {
t = 1;
} else {
t = t / mAnimationTimeFraction;
}
final DragView dragView = (DragView) mDragLayer.getAnimatedView();
final float time = t * mDuration;
dragView.setTranslationX(time * mUX + mFrom.left + mAX * time * time / 2);
dragView.setTranslationY(time * mUY + mFrom.top + mAY * time * time / 2);
dragView.setAlpha(1f - mAlphaInterpolator.getInterpolation(t));
}
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
if (hasView()) {
float animatedFraction = valueAnimator.getAnimatedFraction();
if (mWidth != null) {
mParams.width = (int) calculateAnimatedValue(mWidth.mFrom, mWidth.mTo, animatedFraction);
}
if (mHeight != null) {
mParams.height = (int) calculateAnimatedValue(mHeight.mFrom, mHeight.mTo, animatedFraction);
}
mView.get().requestLayout();
}
}
@Override
public void onAnimationUpdate(ValueAnimator animation) {
final float fraction = animation.getAnimatedFraction();
final int height = mRecyclerHeight + (int)(mHeightDelta * fraction + .5F);
final ViewGroup.LayoutParams params = mRecyclerView.getLayoutParams();
params.height = height;
mRecyclerView.requestLayout();
}
@Override
public void onAnimationUpdate(ValueAnimator animation) {
float scale = animation.getAnimatedFraction();
float diffLeft = (targetViewport.left - startViewport.left) * scale;
float diffTop = (targetViewport.top - startViewport.top) * scale;
float diffRight = (targetViewport.right - startViewport.right) * scale;
float diffBottom = (targetViewport.bottom - startViewport.bottom) * scale;
newViewport.set(startViewport.left + diffLeft, startViewport.top + diffTop, startViewport.right + diffRight,
startViewport.bottom + diffBottom);
chart.setCurrentViewport(newViewport);
}
@Override
public void onAnimationUpdate(ValueAnimator animation) {
float scale = animation.getAnimatedFraction();
float rotation = startRotation + (targetRotation - startRotation) * scale;
rotation = (rotation % 360 + 360) % 360;
chart.setChartRotation((int) rotation, false);
}
@Override
public void onAnimationUpdate(ValueAnimator animation) {
float scale = animation.getAnimatedFraction();
float rotation = startRotation + (targetRotation - startRotation) * scale;
rotation = (rotation % 360 + 360) % 360;
chart.setChartRotation((int) rotation, false);
}
@Override
public void onAnimationUpdate(ValueAnimator animation) {
final float factor = animation.getAnimatedFraction();
mTouchSpotRadius = (int) (mTargetRadius * factor);
mTouchSpotPaint.setColor(transformAlpha(mTouchSpotColor, 0x00, 0x38, factor));
mBackgroundDrawable.getPaint().setColor(transformColor(mBackgroundColorDarker, mBackgroundColor, factor));
invalidate();
}
@Override
public void onAnimationUpdate(ValueAnimator animation) {
int alpha = (int) (255 * animation.getAnimatedFraction());
mClockPaint.setAlpha(alpha);
mInfoPaint.setAlpha(alpha);
// if we are going to get displayed update data
if (alpha > 0 && mStaleData) {
updateData();
mStaleData = false;
}
}
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
float fraction = valueAnimator.getAnimatedFraction();
double lat = (to.latitude - from.latitude) * fraction + from.latitude;
double lngDelta = to.longitude - from.longitude;
// Take the shortest path across the 180th meridian.
if (Math.abs(lngDelta) > 180) {
lngDelta -= Math.signum(lngDelta) * 360;
}
double lng = lngDelta * fraction + from.longitude;
LatLng position = new LatLng(lat, lng);
marker.setPosition(position);
}
@Override
public void onAnimationUpdate(ValueAnimator animation) {
float t = animation.getAnimatedFraction();
if (t > mAnimationTimeFraction) {
t = 1;
} else {
t = t / mAnimationTimeFraction;
}
final DragView dragView = (DragView) mDragLayer.getAnimatedView();
final float time = t * mDuration;
dragView.setTranslationX(time * mUX + mFrom.left + mAX * time * time / 2);
dragView.setTranslationY(time * mUY + mFrom.top + mAY * time * time / 2);
dragView.setAlpha(1f - mAlphaInterpolator.getInterpolation(t));
}
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
mOpenAnimationProgress = valueAnimator.getAnimatedFraction();
}
@Override
public void onAnimationUpdate(ValueAnimator animation) {
mLastUpdatedAnimation = animation;
mLastAnimatedFraction = animation.getAnimatedFraction();
updateAnimation(mLastUpdatedAnimation, mLastAnimatedFraction);
}