TranslateAnimation动画移动后ImageView自身x y坐标不会改变问题

   例如:

TranslateAnimation(float fromXDelta, float toXDelta, float fromYDelta, float toYDelta)这个是相对自身的就对坐标的移动,但移动后执行该动画的View自身X Y值不变,当手动设置坐标时,如

               view.setX(x);

               view.setY(y);

view的显示位置不会在当前的x,y坐标位置,而是在相对该位置执行过anim后的位置,而事件可以在该位置触发。

解决方案:使用Animation的监听

实例:  

ImageView img = new ……  创建ImageView

   

TranslateAnimation anim = new TranslateAnimation( 0, x, 0,y);


anim.setFillAfter(true);//设置移动后留在当前位置,不返回


anim.setDuration(500);

anim.setInterpolator(mAcitvity,android.R.anim.accelerate_decelerate_interpolator);


img.startAnimation(anim);

//设置动画监听器, 在监听到动画结束时清除img动画,设置img x,y坐标

anim.setAnimationListener(new AnimationListener() {

@Override

public void onAnimationStart(Animation animation) {

// TODO Auto-generated method stub

}

@Override

public void onAnimationRepeat(Animation animation) {

// TODO Auto-generated method stub

}

@Override

public void onAnimationEnd(Animation animation) {

// TODO Auto-generated method stub

   img.clearAnimation();

   img.setX(x);

   img.setY(y);

}

});