Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getLocationOnScreen() returns zero

Tags:

android

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

like image 639
sam Avatar asked Oct 25 '13 06:10

sam


1 Answers

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);
}
like image 103
Hariharan Avatar answered Nov 12 '22 20:11

Hariharan