Я пытаюсь создать свою собственную пользовательскую анимацию, которая будет перемещать и масштабировать вид.Android move and scale custom animation
public class MoveAndSizeAnimation extends Animation implements Animation.AnimationListener{
View view;
float fromX;
float fromY;
float fromWidth;
float fromHeight;
float toX;
float toY;
float toWidth;
float toHeight;
public MoveAndSizeAnimation(View v, float toX, float toY, float toWidth, float toHeight, int duration) {
this.view = v;
this.toX = toX;
this.toY = toY;
this.toWidth = toWidth;
this.toHeight = toHeight;
fromX = v.getX();
fromY = v.getY();
fromWidth = v.getWidth();
fromHeight = v.getHeight();
this.setInterpolator(new AccelerateDecelerateInterpolator());
setDuration(duration);
}
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
float newX = fromX + (toX - fromX) * interpolatedTime;
float newY = fromY + (toY - fromY) * interpolatedTime;
float newWidth = fromWidth + (toWidth - fromWidth) * interpolatedTime;
float newHeight = fromHeight + (toHeight - fromHeight) * interpolatedTime;
float scaledWidth = newWidth/fromWidth;
float scaledHeight = newHeight/fromHeight;
view.setX(newX);
view.setY(newY);
view.requestLayout();
}
@Override
public boolean willChangeBounds() {
return false;
}}
Движущаяся анимация в порядке, но не может получить масштабирование справа. Я попытался установить макет видаParams, но он действительно изменил ширину и высоту представления. Я хочу только масштабировать.
Может ли кто-нибудь помочь?
или как я могу узнать, как работает класс ScaleAnimation, предоставляемый Android?