2016-06-08 2 views
0

Я пытаюсь создать свою собственную пользовательскую анимацию, которая будет перемещать и масштабировать вид.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?

ответ

0

ОК, так что ответ должен использовать scaleX и scaleY и не забудьте установить setPivotX (0.5f) и setPivotY (0.5f) .. вот и все ..