下面列出了android.view.animation.Animation#setFillEnabled() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void moveView(int fromPosition, int toPosition) {
if (DEBUG_LOG) {
L.d(TAG, "moveView from:" + fromPosition + ",to:" + toPosition);
}
final View from = getView(fromPosition);
final View to = getView(toPosition);
final Rect fromRect = new Rect();
getLayout(from, fromRect);
final Rect toRect = new Rect();
getLayout(to, toRect);
Animation translate = new TranslateAnimation(0, toRect.left
- fromRect.left, 0, toRect.top - fromRect.top);
translate.setDuration(150);
translate.setFillEnabled(true);
translate.setFillBefore(true);
translate.setFillAfter(true);
translate.setAnimationListener(new MoveViewAnimationListener(from, to
.getLeft(), to.getTop()));
from.startAnimation(translate);
}
/**
* Creates the moving animation
* <p>
* Configures the moving animation based on moving params
*
* @param params params, which is used to configure the moving animation
* @return moving animation
*/
private Animation createAnimation(MovingParams params) {
Animation animation = new TranslateAnimation(0, params.getXAxisDelta(), 0, params.getYAxisDelta());
animation.setFillEnabled(true);
animation.setFillBefore(false);
animation.setDuration(params.getAnimationDuration());
Interpolator interpolator = params.getAnimationInterpolator();
if (interpolator != null) {
animation.setInterpolator(interpolator);
}
animation.setAnimationListener(new MoveAnimationListener(params));
return animation;
}
private void init() {
final LayoutParams tempFigureLayoutParams = new LayoutParams(this.diameter, this.diameter);
tempFigureLayoutParams.gravity = Gravity.CENTER;
for (int i = 0; i < this.figureViews.length; i++) {
final FigureView figureView = new FigureView(getContext());
figureView.setColor(this.colors[i]);
figureView.setFigureMargin(this.marginFigureCounter += this.marginFigure);
if (this.isRounded) {
figureView.setRounded();
}
Animation tempAnimation = new RotateAnimation(0, this.angle, this.radius, this.radius);
tempAnimation.setStartOffset(this.startOffsetCounter);
tempAnimation.setDuration(this.speed - this.startOffsetCounter);
this.startOffsetCounter -= this.startOffset;
figureView.setDrawingCacheEnabled(true);
tempAnimation.setFillEnabled(true);
tempAnimation.setFillBefore(true);
tempAnimation.setFillAfter(true);
tempAnimation.setRepeatMode(Animation.RESTART);
tempAnimation.setRepeatCount(Animation.INFINITE);
tempAnimation.setInterpolator(new AccelerateDecelerateInterpolator());
figureView.startAnimation(tempAnimation);
figureView.setLayoutParams(tempFigureLayoutParams);
this.figureViews[i] = figureView;
this.addView(figureView);
}
if (this.isRotated) {
final Animation spinningAnimation = new RotateAnimation(0, 360, this.radius, this.radius);
spinningAnimation.setDuration(this.speed * 5);
spinningAnimation.setInterpolator(new LinearInterpolator());
spinningAnimation.setRepeatMode(Animation.RESTART);
spinningAnimation.setRepeatCount(Animation.INFINITE);
startAnimation(spinningAnimation);
}
}
public Animation instantiate(Context c) {
Animation anim = createAnimation(c);
if (null != anim) {
if (null != detachWallpaper) {
anim.setDetachWallpaper(detachWallpaper);
}
if (null != duration) {
anim.setDuration(duration);
}
if (null != fillAfter) {
anim.setFillAfter(fillAfter);
}
if (null != fillBefore) {
anim.setFillBefore(fillBefore);
}
if (null != fillEnabled) {
anim.setFillEnabled(fillEnabled);
}
if (null != interpolator) {
Interpolator i = loadInterpolator(c, interpolator);
if (null != i) {
anim.setInterpolator(i);
}
}
if (null != repeatCount) {
anim.setRepeatCount(repeatCount);
}
if (null != repeatMode) {
anim.setRepeatMode(repeatMode);
}
if (null != startOffset) {
anim.setStartOffset(startOffset);
}
if (null != zAdjustment) {
anim.setZAdjustment(zAdjustment);
}
}
return anim;
}