2012-09-10 20 views
10

Birisi Android animasyonlarını biliyor mu? Aşağıdaki gibi bir şey oluşturmak istiyorum:Android'de animasyonları taşıma/yeniden boyutlandırma nasıl oluşturulur?

  • Aygıt ekranımın ortasında büyük bir görüntüm var;
  • Bu resim küçük (animasyona göre) hale gelir ve cihaz ekranımın köşesine gider;
bu körük sırayla gibi

Onun şey: Herhangi İpuçları çok mutluluk duyacağız

enter image description here

! Şimdiden teşekkürler!

cevap

8

scaleXBy() ve translateYBy() gibi yöntemlerle ViewPropertyAnimator kullanın. API Seviye 11+ üzerinde View numaralı telefondan animate() numaralı telefonu arayarak ViewPropertyAnimator olsun. Eski cihazları destekliyorsanız, NineOldAndroids, neredeyse işyerinde bir arka destek sunmaktadır.

Ayrıca okumak isteyebilirsiniz:

+0

Teşekkürler CommonsWare. Surelly, bu harika bir yardım! – mthama

7

Ben eşzamanlı dönüşü ve hareket ile bir sınıf var. Bu pahalı ama tüm API sürümlerinde çalışır.

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 ... iyi çalışıyor – Houston

+0

Bu harika çalışıyor! Teşekkürler! – instanceof

+0

Bu yeniden boyutlandırma animasyonunu, söz konusu görünümle nasıl arayabiliriz? – shobhan

İlgili konular