Android 在动画结束后获取布局的新位置

Android 在动画结束后获取布局的新位置,android,translate-animation,Android,Translate Animation,小问题,在android中,在使用TranslateImation之后,您如何获得它所占据的位置 在我的应用程序中,当用户触摸图像时,它会向上移动并显示一个输入屏幕。 但是当图像到达它的最终位置时,我想将图像粘贴到它的新位置。 但是当我使用getHeight或getLayoutParams时,我总是得到旧的位置 public void moveProducts() { float addAmmountY = -250; TranslateAnimation anim = new

小问题,在android中,在使用TranslateImation之后,您如何获得它所占据的位置

在我的应用程序中,当用户触摸图像时,它会向上移动并显示一个输入屏幕。 但是当图像到达它的最终位置时,我想将图像粘贴到它的新位置。 但是当我使用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);
}试试这个:

@Override
public void onAnimationEnd(Animation animation) {
   product_buttons.requestLayout();
}
动画完成后,尝试获取图像的新位置