1

我有一个Drawable对象,我想在屏幕上找到绝对坐标。我发现的所有函数都与相对坐标有关,而不是绝对坐标。

这是代码:

public class MainActivity extends Activity {

AnimationDrawable rocketAnimation;
int counter = 0;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    ImageView rocketImage = (ImageView) findViewById(R.id.ball_laugh);
    rocketImage.setBackgroundResource(R.drawable.frames);
    rocketAnimation = (AnimationDrawable) rocketImage.getBackground();
    rocketAnimation.start()
}

public boolean onTouchEvent(MotionEvent event) {
      if (event.getAction() == MotionEvent.ACTION_DOWN) {

         // Get the frame of the animation
         Drawable currentFrame;
         currentFrame = rocketAnimation.getCurrent();

         // Now I want to get the x,y coordinates of currentFrame..   

        return true;
      }
      return super.onTouchEvent(event);
    }
}
4

0 回答 0