2015-02-06 18 views
-1

我一直在嘗試在android中創建動畫視圖,並且我已經完成了該動畫,但問題在於動畫卡在中間的某些時候我不知道爲什麼。爲什麼有時動畫卡在Android上?

我正在做的是我有一個在中間的視圖,該視圖包含水平列表視圖,當一個項目被點擊時,視圖動畫頂部和頂部,當用戶點擊它下降到其原始位置

這裏是動畫代碼。

public class DropDownAnim extends Animation { 
private final float targetHeight; 
private final View view; 
private final boolean down; 


public DropDownAnim(View view, float targetHeight, boolean down) { 
    this.view = view; 
    this.targetHeight = targetHeight; 
    this.down = down; 
} 

@Override 
protected void applyTransformation(float interpolatedTime, Transformation t) { 
    int newHeight; 
    if (down) { 
     newHeight = (int) (targetHeight * interpolatedTime); 
    } else { 
     newHeight = (int) (targetHeight * (1 - interpolatedTime)); 
    } 
    view.getLayoutParams().height = newHeight; 
    view.requestLayout(); 


} 

    @Override 
    public void initialize(int width, int height, int parentWidth, 
         int parentHeight) { 
    super.initialize(width, height, parentWidth, parentHeight); 
    } 

    @Override 
    public boolean willChangeBounds() { 
    return true; 
    } 
} 

當包含水平列表視圖和一個項目被點擊我做

DropDownAnim drop = new DropDownAnim(_View, (width_And_Height[1]/100) * 
        Utils.get_Percentage_For_animate_View_Based_On_Mobile_Resloution(), 
       true); //true means go to top 
     drop.setDuration(DURATION); 
     _View.setAnimation(drop); 
     _View.startAnimation(drop); 

和當視圖頂部

DropDownAnim drop = new DropDownAnim(_View, (width_And_Height[1]/100) * Utils.get_Percentage_For_animate_View_Based_On_Mobile_Resloution(), 
        false);//false means go to is orignal position 
      drop.setDuration(DURATION); 
      _View.setAnimation(drop); 
      _View.startAnimation(drop); 

這是回訪的觀點屏幕的高度。

width_And_Height[1] 

當水平滾動視圖是在中心,我就瘋狂點擊上升,當水平滾動視圖是在上面,我點擊地圖談到了一部開拓創新位置第一。

但現在的問題是,有時認爲不來了,從頂部的一部開拓創新的位置,卡在中間

這裏的圖像。

當水平滾動視圖是在屏幕

的中間時,水平滾動視圖是在頂部屏幕的

enter image description here

當這種觀點並沒有從最高層和最高層來到原來的位置科軍在中間

enter image description here

我不知道是什麼問題

感謝的製作時間,我的問題,並請幫助:)

+0

當你投下一個問題或答案,請給出理由...... – 2015-02-09 15:42:38

+0

請刪除視圖。requestLayout()from applyTransformation並在動畫開始後只寫一次 – 2015-02-14 05:24:15

回答

1

我不知道你爲什麼正在擴展一個動畫。如果您嘗試更改視圖的位置或高度,則應該使用PropertyAnimations。

如果您試圖增長視圖,請使用簡單的ObjectAnimator並執行以下操作。

ObjectAnimator animation = ObjectAnimator.ofFloat(mView,"scaleX",0,2); 
animation.setDuration(duration); 
animation.start(); 
+0

sory for late rep我不想移動視圖,而是向上移動並展開視圖 – 2015-02-27 06:42:18

+0

向上移動。當你說擴大觀點時你是什麼意思。儘管這兩個擴展動畫是不正確的,如果你想動畫的視圖屬性。這就是爲什麼我建議你使用ObjecrAnimators。 – Elliott 2015-02-27 09:35:59

相關問題