Итак, у меня есть ImageView, где я устанавливаю png в качестве фона. Предположим, что png-изображение - это круг, поэтому он не занимает все пространство ImageView. Мне нужно поймать событие, щелкнув только содержимое ImageView (круг), а не оставшуюся пустую область. Возможно ли это вообще или с любым другим элементом управления Android?Координаты содержания ImageView
Редактировать: Я до сих пор не могу заставить это работать. Так, чтобы быть более точным у меня есть эта картина яйца, которые я поставил в ImageView ЦСИ
И я хочу, чтобы иметь возможность только нажать на него. Например, если я слегка щелкнул за пределами яйца, я хочу знать это и предотвратить код внутри события клика ImageView.
Я попробовал этот код, но я не имею ни малейшего представления, как это помогает мне:
ImageView imageView = (ImageView)findViewById(R.id.imageview);
Drawable drawable = imageView.getDrawable();
Rect imageBounds = drawable.getBounds();
//original height and width of the bitmap
int intrinsicHeight = drawable.getIntrinsicHeight();
int intrinsicWidth = drawable.getIntrinsicWidth();
//height and width of the visible (scaled) image
int scaledHeight = imageBounds.height();
int scaledWidth = imageBounds.width();
//Find the ratio of the original image to the scaled image
//Should normally be equal unless a disproportionate scaling
//(e.g. fitXY) is used.
float heightRatio = intrinsicHeight/scaledHeight;
float widthRatio = intrinsicWidth/scaledWidth;
//do whatever magic to get your touch point
//MotionEvent event;
//get the distance from the left and top of the image bounds
int scaledImageOffsetX = event.getX() - imageBounds.left;
int scaledImageOffsetY = event.getY() - imageBounds.top;
//scale these distances according to the ratio of your scaling
//For example, if the original image is 1.5x the size of the scaled
//image, and your offset is (10, 20), your original image offset
//values should be (15, 30).
int originalImageOffsetX = scaledImageOffsetX * widthRatio;
int originalImageOffsetY = scaledImageOffsetY * heightRatio;
Проверьте ссылку HTTP://stackoverflow.com/questions/11334984/correspondence-between-imageview-coordinates-and-bitmap-pixels-android и http://stackoverflow.com/questions/11311337/select-content-inside-imageview-android, это поможет вам –