title: How to print coordinates of a view in the Logcat?
body: <p>I am trying to print the coordinates of the view in the Logcat, but the values shown for x and y coordinates of the view are 0,0.</p>
  
  <p>I am able to print the values in the onclickListner method, but the values of x and y 0,0 outside the method.</p>
  
  <p>public class MainActivity extends AppCompatActivity {</p>
  
  <pre><code>public TextView textView;
  public Button mButton;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      textView = findViewById(R.id.textview);
      mButton = findViewById(R.id.button);
  
      int[] location = new int[2];
  
      textView.getLocationOnScreen(location);
      Log.v("location","value" +location[0]);
      Log.v("location","value" +location[1]);
  
  
      mButton.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              int[] location = new int[2];
  
              textView.getLocationOnScreen(location);
              Log.v("location","value" +location[0]);
              Log.v("location","value" +location[1]);
  
              textView.setText("Button location\nx = "+location[0]+"\ny = "+ location[1]);
          }
      });
  }
  </code></pre>
  
  <p>I am expecting the log values for textView coordinates from the the statements before onClicklisterner.  </p>