我有一个在ImageView中进行平移动画的子弹图像。
我需要实时显示坐标以展示其与目标的距离。
ImageView myimage = (ImageView)findViewById(R.id.myimage);
Animation animation = new TranslateAnimation(100, 200, 300, 400);
animation.setDuration(1000);
myimage.startAnimation(animation);
animation.setRepeatCount(Animation.INFINITE);
在使用TranslateAnimation时,是否可以获取图像的实时x和y坐标?
如果无法使用TranslateAnimation,是否有其他方法可以在运动过程中实时获得图像的坐标?
我尝试过 -
int x = myimage.getLeft();
int y = myimage.getTop();
和
int[] firstPosition = new int[2];
myimage.measure(View.MeasureSpec.EXACTLY, View.MeasureSpec.EXACTLY);
myimage.getLocationOnScreen(firstPosition);
int x = firstPosition[0];
int y = firstPosition[1];
但在两种方式中,它都会给出ImageView的初始静态坐标。