我有ImageView
,但如何才能看到用户在图片上点击/触摸的位置。
我知道我必须使用MotionEvent.getX()
和MotionEvent.getY()
,但如何才能看到用户点击图片的位置?
谢谢!
答案 0 :(得分: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;
}