我创建了一个CustomView
extends View
。创建一些CustomView
并使用动画来移动和旋转它们。发生更改backgroundResource
和错误后,新背景不会全部填满CustomView
。请看代码:
clearAnimation();
AnimationSet animation = new AnimationSet(true);
TranslateAnimation translateAnimation = new TranslateAnimation(0, destX - srcX, 0, destY - srcY);
translateAnimation.setInterpolator(new LinearInterpolator());
translateAnimation.setDuration((long) MGConstant.ANIMATE_DURATION);
animation.addAnimation(translateAnimation);
final float finalX = destX;
final float finalY = destY;
animation.setAnimationListener(new AnimationListener() {
public void onAnimationEnd(Animation arg0) {
clearAnimation();
setX(finalX);
setY(finalY);
RotateAnimation rotateAnimation = new RotateAnimation(0, degrees, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
rotateAnimation.setInterpolator(new LinearInterpolator());
rotateAnimation.setDuration((long) MGConstant.ANIMATE_DURATION);
rotateAnimation.setFillAfter(true);
startAnimation(rotateAnimation);
resetLayout();
mMoveStatus = false;
degree = degrees;
}
public void onAnimationRepeat(Animation arg0) {
}
public void onAnimationStart(Animation arg0) {
}
});
startAnimation(animation);
并重置布局:
lp = (LayoutParams) getLayoutParams();
if (lp == null) {
Log.d(TAG, "FIRST");
lp = new LayoutParams((int) cardW, (int) cardH);
lp.leftMargin = (int) mX;
lp.topMargin = (int) mY;
} else {
Log.d(TAG, "LAST");
lp.leftMargin = (int) mX;
lp.topMargin = (int) mY;
}
setLayoutParams(lp);
请帮我