2

私は持ってImageViewいますが、ユーザーが画像をクリック/タッチした場所をどのように確認できますか。

MotionEvent.getX()とを使用する必要があることはわかっていMotionEvent.getY()ますが、ユーザーが画像をクリックした場所を確認するにはどうすればよいですか?

ありがとう !

4

1 に答える 1

2

画像ビューをサブクラス化し、ユーザーが触れている位置にインジケーターを明示的に描画する必要があります。

public class TouchableImageView extends ImageView {

  // Constructors should come here

  // Override onTouch to remember the touch position in our variable touchLocation
  // Set touchLocation to null when getting the ACTION_UP event

  // Override onDraw to draw something at touchLocation. You should create a proper Paint object
  // in your constructors and use it here
  public void onDraw(Canvas c) {
    if (touchLocation!=null) {
      canvas.drawCircle(touchLocation.x, touchLocation.y, 10, indicatorPaint);
    }
  }

  private Point touchLocation;
  private Paint indicatorPaint;
}
于 2012-10-23T08:24:28.020 に答える