2012-09-10 180 views
10

有人知道Android動畫嗎?我想要創建如下內容:如何在Android中創建移動/調整動畫大小?

  • 我在設備屏幕的中心有一個大圖像;
  • 這個圖像變得很小(通過動畫),並轉到我的設備屏幕的一角;

它像在這種波紋管順序:

enter image description here

任何提示將是非常讚賞!提前致謝!

回答

8

使用ViewPropertyAnimator,使用方法如scaleXBy()translateYBy()。您通過在API Level 11+上的View上致電animate()獲得ViewPropertyAnimator。如果您支持較舊的設備,則NineOldAndroids可提供接近工作的回送。

您可能還希望閱讀:

+0

感謝CommonsWare。當然,這有很大的幫助! – mthama

7

我與同步旋轉和運動的一類。這是昂貴的,但它適用於所有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

葉...工作正常 – Houston

+0

這工作出色!謝謝! – instanceof

+0

我們如何使用所提到的視圖來調用這個調整大小的動畫 – shobhan

相關問題