I have an vector/PNG image on a image view. I need to track where the user touches on the image and mark the points. I have done this part. But I am facing a problem. Since the image shape is irregular, there is space between image and image view (rectangle) boundaries.
If the user touches the imageview but not the image (ie) the space between the boundaries, these points should not be marked. Is there a way to do this ?
imageView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
modelWidth = selected_Car_Image.getWidth();
modelHeight = selected_Car_Image.getHeight();
float xTouchCoordinate = motionEvent.getX();
float yTouchCoordinate = motionEvent.getY();
return false;
}
});
}
<RelativeLayout
android:id="@+id/carImageViewLayout"
android:layout_width="200dp"
android:layout_height="match_parent"
android:layout_centerHorizontal="true">
<ImageView
android:id="@+id/imageView"
android:layout_width="200dp"
android:layout_height="400dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" />
</RelativeLayout>
And I use xTouchCoordinate and yTouchCoordinate to draw a point as when the user touches.
In this example, I dont wan't to track any points that the user clicks outside the laptop. But if the user clicks on the laptop I need those points.