am using the following code for getting the position of a button but it always returning zero. Why this happening
Button b=(Button) findViewById(R.id.button2);
final int[] x=new int[2];
b.getLocationOnScreen(x);
Iam sure someone here can help me
Try this..
Button b;
in Globel variable
then onCreate()
b=(Button) findViewById(R.id.button2);
After onCreate();
@Override
public void onWindowFocusChanged (boolean hasFocus) {
final int[] x=new int[2];
b.getLocationOnScreen(x);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With