Android:在TranslateImation之后刷新视图位置?
例如,我使用TranslateAnimation将ImageView从0,0移动到200,0 当onAnimationEnd发生时,我需要一种方法来获取ImageView的新位置。我尝试了getLocationInWindow()、getLocationOnScreen()和getLeft()方法,但该位置从未刷新 以下是以下代码的结果:Android:在TranslateImation之后刷新视图位置?,android,animation,view,position,Android,Animation,View,Position,例如,我使用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/tes
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());
}
});
谢谢 你得到了视图的位置——它不会移动,因此也不会改变。你解决过这个问题吗,我面临着完全相同的问题?