2
我有一個ImageView
,但我怎麼能看到用戶有點擊/觸及在圖像上。Android SDK獲取點擊圖片
我知道我必須使用MotionEvent.getX()
和MotionEvent.getY()
,但是如何查看用戶點擊圖像的位置?
謝謝!
我有一個ImageView
,但我怎麼能看到用戶有點擊/觸及在圖像上。Android SDK獲取點擊圖片
我知道我必須使用MotionEvent.getX()
和MotionEvent.getY()
,但是如何查看用戶點擊圖像的位置?
謝謝!
您必須對圖像視圖進行子類化,並在用戶觸摸的位置明確繪製指示器。
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;
}
你能解釋嗎? –
查看編輯答案。 –
謝謝!這非常有用! –