2014-02-06 52 views
0

小問題,在你使用TranslateAnimation之後的android中,你如何獲得它所拍攝的位置。在動畫結束後獲取佈局的新位置

在我的應用程序中,當用戶觸摸圖像時,它會向上移動並顯示輸入屏幕。 但是當圖像達到最終位置時,我想將圖像粘貼到新的位置。 但是,當我使用getHeight或getLayoutParams我總是得到舊的位置。

public void moveProducts() { 
    float addAmmountY = -250; 
    TranslateAnimation anim = new TranslateAnimation(0,0,0,addAmmountY); //(float fromXDelta, float toXDelta, float fromYDelta, float toYDelta) 
    anim.setDuration(1000); 

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

anim.setAnimationListener(new TranslateAnimation.AnimationListener() { 
    @Override 
    public void onAnimationStart(Animation animation) { 
    } 

    @Override 
    public void onAnimationRepeat(Animation animation) { 
    } 

    @Override 
    public void onAnimationEnd(Animation animation) { 
     //TODO set new location of the linearlayout 
    } 
}); 


product_buttons.startAnimation(anim); 

}

回答

0

試試這個:

@Override 
public void onAnimationEnd(Animation animation) { 
    product_buttons.requestLayout(); 
} 

動畫後試圖獲取圖像的新位置。

相關問題