我正在使用TranslateAnimation将ImageView从0,0移动到200,0,例如
当onAnimationEnd发生时,我需要一种方法来获取ImageView的新位置。我尝试了getLocationInWindow(),getLocationOnScreen()和getLeft()方法,但该位置永远不会刷新。
以下代码的结果如下:
02-03 13:18:03.600: E/test(22898): onAnimationStart !
02-03 13:18:03.600: E/test(22898): getLocationInWindow : 90 , 70
02-03 13:18:03.600: E/test(22898): getLocationOnScreen : 90 , 70
02-03 13:18:03.600: E/test(22898): getLeft : 0
02-03 13:18:06.590: E/test(22898): onAnimationEnd !
02-03 13:18:06.590: E/test(22898): getLocationInWindow : 90 , 70
02-03 13:18:06.590: E/test(22898): getLocationOnScreen : 90 , 70
02-03 13:18:06.590: E/test(22898): getLeft : 0
final TranslateAnimation ta = new TranslateAnimation(0, 200, 0, 0);
ta.setDuration(3000);
ta.setFillAfter(true);
ivCurseurMoyenneComportement.startAnimation(ta);
ta.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(final Animation arg0) {
Log.e("test", "onAnimationStart !");
final int[] loc = new int[2];
ivCurseurMoyenneComportement.getLocationInWindow(loc);
Log.e("test", "getLocationInWindow : " + loc[0] + " , "
+ loc[1]);
ivCurseurMoyenneComportement.getLocationOnScreen(loc);
Log.e("test", "getLocationOnScreen : " + loc[0] + " , "
+ loc[1]);
Log.e("test",
"getLeft : "
+ ivCurseurMoyenneComportement.getLeft());
}
@Override
public void onAnimationRepeat(final Animation arg0) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationEnd(final Animation arg0) {
Log.e("test", "onAnimationEnd !");
final int[] loc = new int[2];
ivCurseurMoyenneComportement.getLocationInWindow(loc);
Log.e("test", "getLocationInWindow : " + loc[0] + " , "
+ loc[1]);
ivCurseurMoyenneComportement.getLocationOnScreen(loc);
Log.e("test", "getLocationOnScreen : " + loc[0] + " , "
+ loc[1]);
Log.e("test",
"getLeft : "
+ ivCurseurMoyenneComportement.getLeft());
}
});
谢谢!