2012-02-06 58 views
6

我試圖動畫UI元素。我想從中間移到一個EditText和一個按鈕在表格下方他們一個HTTP調用的屏幕和顯示結果的頂部。這將是巨大的,如果任何人都可以點我在正確的方向,在這一點上,我不知道我閹應該使用Java或XML這一點。Android的UI元素的動畫

在此先感謝。

回答

8

用翻譯框架,以實現這一目標,該工程爲:

TranslateAnimation(float fromXDelta, float toXDelta, float fromYDelta, float toYDelta) 

所以,你需要寫你在y軸方向移動視圖代碼,如下所示:

mAnimation = new TranslateAnimation(0, 0, 0, 599); 
    mAnimation.setDuration(10000); 
    mAnimation.setFillAfter(true); 
    mAnimation.setRepeatCount(-1); 
    mAnimation.setRepeatMode(Animation.REVERSE); 
    view.setAnimation(mAnimation); 

這裏查看可以是任何東西,TextView的,ImageView的等

+0

謝謝,這正是我一直在尋找的。 – Meatje 2012-02-07 09:36:35

1

接受的答案引起了錯誤我的代碼裏面,下面的代碼片段幾乎等同於接受的答案& WO在不造成錯誤的情況下,將對象從屏幕上滑下。我需要手勢綁鍵盤也「滑走」,並從TranslateAnimation切換到ObjectAnimator(以下代碼第二塊)。

final LinearLayout keyPad = (LinearLayout)findViewById(R.id.keyPad); 

moveKeyPadUp(keyPad); 

private void moveKeyPadUp(LinearLayout keyPad){ 
     Animation animation = new TranslateAnimation(0,0,0,-500); 
     animation.setDuration(1000); 
     animation.setFillAfter(true); 
     keyPad.startAnimation(animation); 
} 

private void moveKeyPadUpdated(LinearLayout keyPad){ 
     ObjectAnimator mover = ObjectAnimator.ofFloat(keyPad,"translationY",0,-500); 
     mover.setDuration(300); 
     mover.start(); 
}