2012-09-10 10 views
10

¿Alguien sabe acerca de las animaciones de Android? Quiero crear algo como lo siguiente:¿Cómo crear mover/cambiar el tamaño de animaciones en Android?

  • Tengo una imagen grande en el centro de la pantalla de mi dispositivo;
  • esta imagen se vuelve pequeña (por animación) y va a la esquina de la pantalla de mi dispositivo;

Su algo así en esta secuencia abajo:

enter image description here

Alguna pista serían muy apreciados! ¡Gracias por adelantado!

Respuesta

8

Use ViewPropertyAnimator, con métodos como scaleXBy() y translateYBy(). Obtienes un ViewPropertyAnimator llamando al animate() en un View, en el nivel 11+ de la API. Si está admitiendo dispositivos más antiguos, NineOldAndroids ofrece un backport cercano al trabajo.

También puede ser que desee leer:

+0

Gracias CommonsWare. ¡Por supuesto, esto es de gran ayuda! – mthama

7

tengo una clase con la rotación simultánea y el movimiento. Es costoso pero funciona en todas las versiones de API.

public class ResizeMoveAnimation extends Animation { 
    View view; 
    int fromLeft; 
    int fromTop; 
    int fromRight; 
    int fromBottom; 
    int toLeft; 
    int toTop; 
    int toRight; 
    int toBottom; 

    public ResizeMoveAnimation(View v, int toLeft, int toTop, int toRight, int toBottom) { 
     this.view = v; 
     this.toLeft = toLeft; 
     this.toTop = toTop; 
     this.toRight = toRight; 
     this.toBottom = toBottom; 

     fromLeft = v.getLeft(); 
     fromTop = v.getTop(); 
     fromRight = v.getRight(); 
     fromBottom = v.getBottom(); 

     setDuration(500); 
    } 

    @Override 
    protected void applyTransformation(float interpolatedTime, Transformation t) { 

     float left = fromLeft + (toLeft - fromLeft) * interpolatedTime; 
     float top = fromTop + (toTop - fromTop) * interpolatedTime; 
     float right = fromRight + (toRight - fromRight) * interpolatedTime; 
     float bottom = fromBottom + (toBottom - fromBottom) * interpolatedTime; 

     RelativeLayout.LayoutParams p = (LayoutParams) view.getLayoutParams(); 
     p.leftMargin = (int) left; 
     p.topMargin = (int) top; 
     p.width = (int) ((right - left) + 1); 
     p.height = (int) ((bottom - top) + 1); 

     view.requestLayout(); 
    } 
} 
+0

yip ... funciona bien – Houston

+0

¡Esto funciona brillantemente! ¡Gracias! – instanceof

+0

¿Cómo llamamos a esta animación de cambio de tamaño con la vista mencionada? – shobhan

Cuestiones relacionadas