2013-06-25 95 views
0

我有一個LinearLayout(稱爲佈局),其高度爲fill_parent,在RelativeLayout中的初始頂邊距爲200dp。 當我點擊一個按鈕時,我想讓topMargin變爲0,展開LinearLayout。 我用下面的代碼:輕輕創建Android動畫

 final RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
       RelativeLayout.LayoutParams.FILL_PARENT, 
       RelativeLayout.LayoutParams.FILL_PARENT); 

    Animation animation = new Animation() { 
       @Override 
       protected void applyTransformation(float interpolatedTime, 
         Transformation t) { 
         int topMargin = (int)((1-interpolatedTime)*200); 
         layoutParams.setMargins(0, topMargin, 0, 0); 
         layout.setLayoutParams(layoutParams); 
         LogThis.debug("topMargin: "+topMargin); 
       } 
    }; 
    animation.setDuration(1000); 
    layout.startAnimation(animation); 

的問題是,雖然它使一個動畫,它不軟。它通過4個步驟完成轉換,因此看起來不太好。

你有什麼想法如何使這種轉變輕柔嗎?

預先感謝您。

編輯

我有這個在第一時刻:

enter image description here

而且動畫後,我想這一點:

enter image description here

隨着TranslationAnimation我得到這個:

enter image description here

回答

1

波濤洶涌的動畫正在發生,因爲這不是應該如何使用動畫。那些要使用Transformation對象傳遞給方法。

但由於您使用的是簡單的翻譯就可以輕鬆實現,使用一個TranslateAnimation像這樣的回答:

translate animation

+0

那輕輕移動的佈局,但它並不按觀測整個空間。我需要它增長(調整佈局,而不是其中的圖像)。 – user1448668