oliverbytes
oliverbytes

Reputation: 644

(Android) Different Coordinates on Different Resolution How to Fix?

I am making a game that the user should Identify the parts of the face of a person. and I should get the coordinates touched on the image,., but I have tried it on different phones / resolution, but I get the different coordinates. how to fix it guys? please I really need help with this

Upvotes: 0

Views: 807

Answers (2)

Kevin McCarpenter
Kevin McCarpenter

Reputation: 786

This may not be the best way to do it, but I had success by doing

double windowWidth = getWindow().getDecorView().getWidth();
double windowHeight = getWindow().getDecorView().getHeight();
float xDensity = event.getX();
double x = (xDensity / windowWidth) * 100;
float yDensity = event.getY();
double y = (yDensity / windowHeight) * 100;

The * 100 isn't necessary; I just have that for display purposes.

Upvotes: 1

Flynn
Flynn

Reputation: 6191

The image should be constructed of different drawable Views, that you can grab the pressed state of.

If you where to use a static image then you cannot use a coordinate system (based on px) because phones and other Android devices do not have the same screen size. Your other option in that way would be to use dip (density independent pixels) instead of px.

Upvotes: 0

Related Questions