Reputation: 1
I am trying to find the coordinates of an image inside of an ImageView, but I can't find a way to get accurate results. Here is the best solution I've found so far.
int[] img_coordinates = new int[2];
plate.getLocationOnScreen(img_coordinates);
int x = img_coordinates[0];
int y = img_coordinates[1];
BitmapFactory.Options o = new BitmapFactory.Options();
o.inTargetDensity = DisplayMetrics.DENSITY_DEFAULT;
Bitmap bmp = BitmapFactory.decodeResource(this.getResources(), R.drawable.plate_only, o);
int w = bmp.getWidth();
int h = bmp.getHeight();
The x value is correct for this, but the y is returning a value in the middle of the upper half of the image. Any suggestions on how to get an accurate y value, and/or a cleaner way of getting these coordinates? Thanks in advance.
Upvotes: 0
Views: 177
Reputation: 11
In getLocationOnScreen() Y value includes status and notification bar height. to exclude this you can take help from this link..
Upvotes: 1