Thank you for your answer.
I have solved my problem in an other way:
- I have divided the height of the screen (e.g. Nexus 4: 1280px -96px (navigation bar) = 1184) through the x-position of the first point (x/y) see picture.
- Then the width…
- Step 1 and 2 with the second point (x2/y2)
http://s14.directupload.net/images/131115/temp/izsvufmy.png
At the end i got the quotients, which I have saved in arrays (double):
//the width
private double[] quotientX = {5.9, 2.4, 1.5, 5.9, 2.4, 1.5, 5.9, 2.4, 1.5, 5.9, 2.4, 1.5, 4.80, 2.95, 1.83, 1.54};
private double[] quotientX2 ={2.8, 1.7, 1.2, 2.8, 1.7, 1.2, 2.8, 1.7, 1.2, 2.8, 1.7, 1.2, 2.79, 1.51, 1.45, 1.27};
//the height
private double[] quotientY = {1.60,1.55,1.60,
1.40,1.35,1.40,
1.25,1.20,1.25,
1.12,1.10,1.12,
1.97,2.23,1.86,2.02};
private double[] quotientY2 = {1.50,1.40,1.50,
1.30,1.25,1.30,
1.15,1.10,1.15,
1.05,1.00,1.05,
1.85,2.01,1.67,1.77};
I haven’t used buttons, but just the view:
image.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
for(int i = 0; i < 16; i++){
if(event.getX() > width/quotientX[i] && event.getX() < width/quotientX2[i] & event.getY() > height/quotientY[i] && event.getY() < height/quotientY2[i]){
//1 to 9 buttons
if(i < 9){
Integer a = new Integer(i)+1;
view.setText(view.getText() + a.toString());
}
//4th row buttons
else if(i == 9){
view.setText(view.getText() + "*");
}else if(i == 10){
view.setText(view.getText() + "0");
}else if(i == 11){
view.setText(view.getText() + "#");
}
//navigation buttons
//delete button
else if(i == 12){
String s = view.getText().toString();
view.setText(s.substring(0, s.length() - 1));
}
//call button
else if(i == 13){
call();
}
}
}
return false;
}
});
This works with every device (every resolution and screen size). What do you think about it?