Android : android touch coordinates normalized for multiple screens

on Saturday, July 5, 2014


I am trying to get the exact touch coordinates for multiple screens. After testing it seems this is not working exactly...



public boolean onTouch(View v, MotionEvent event) {
touchX = (int) event.getX();
touchY = (int) event.getY();

convertedX=touchX/(double)displayWidth;
convertedY=touchY/(double)displayHeight;


then I am saving the converted x/y coordinates....and then when loading on another phone I am translating those coordinates by:



String pivotX = object.getString("pivotx");
String pivotY = object.getString("pivoty");

//convert pivot points
double x =(double)Double.valueOf(pivotX) * displayWidth;
double y =(double)Double.valueOf(pivotY) * displayHeight;
final int pivotConvtertedX=(int) x;
final int pivotConvtertedY=(int) y;


It seems like something is off here...Anyone know what I am missing?


0 comments:

Post a Comment