I want to get X and Y Point of View(ImageButton).
When I try to find X and Y on Click event with below code I get proper X and Y coordinate for View.
ImageButton imagebutton = findviewbyId(R.id.imagebutton);
imagebutton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
int[] posXY = new int[2];
v.getLocationOnScreen(posXY);
x = posXY[0];
y = posXY[1];
Log.d("X and Y Point", x + " " + y);
}
});
But I want X and Y Co-ordinate before Click on view so I try to get X and Y with below code.
ImageButton imagebutton = findviewbyId(R.id.imagebutton);
int[] posXY = new int[2];
imageButton.getLocationOnScreen(posXY);
x = posXY[0];
y = posXY[1];
Log.d("X and Y Point", x + " " + y);
But whenever I try to get X and Y with ClickListener I get X and Y as 0 and 0. So, I do not get Proper X and Y without ClickListener. Could anyone help to solve out what is an actual issue, how can I get Proper X and Y without ClickListener?