2012-09-10 8 views
10

誰かがAndroidのアニメーションについて知っていますか?次のようなものを作成します:Androidでのアニメーションの移動/サイズ変更の作成方法

  • 私は自分のデバイス画面の中央に大きな画像を持っています。
  • このイメージは小さくなり(アニメーションによって)、デバイスの画面の角に移動します。

その本怒鳴るシーケンスのようなもの:

enter image description here

任意のヒントは非常に高く評価されるだろう!前もって感謝します!

答えて

8

scaleXBy()およびtranslateYBy()のような方法でViewPropertyAnimatorを使用してください。 APIレベル11以上のをViewに呼び出して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

yip ...うまく動作します – Houston

+0

これはすごくうまくいきます!ありがとう! – instanceof

+0

このリサイズアニメーションを前述のビューで呼び出す方法 – shobhan

関連する問題