title: Android webview layout - when to set position?
body: <p>I have the following XML:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout android:id="@+id/rl"
      android:background="@color/red"
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent"
      xmlns:android="http://schemas.android.com/apk/res/android"&gt;
      &lt;WebView xmlns:android="http://schemas.android.com/apk/res/android"
          android:id="@+id/webview"
          android:layout_width="10dp"
          android:layout_height="10dp" /&gt;
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>When I call:</p>
  
  <pre><code>view.layout(50, 50, 1024 - 50, 600 - 50);
  </code></pre>
  
  <p>from onCreate() and onStart(), it has no effect. But when I add the same call to shouldOverrideKeyEvent() and press a key, it works. I think it's because my settings are being overriden by XML's ones. So, the question is: when should I call layout() as soon as possible, but after android:layout_width="10dp" and android:layout_height="10dp" are already applied.</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I use the solution by blessenm.</p>
  
  <pre><code>private class LayoutListener implements OnGlobalLayoutListener
  {
      public void onGlobalLayout()
      {
          Display display = getWindowManager().getDefaultDisplay();
          int screenWidth = display.getWidth();
          int screenHeight = display.getHeight();
  
          // Workaround for a 'fill_parent' bug on my tablet (Kindle Fire).
          _WebView.layout(0, 0, screenWidth, screenHeight);
          _WebView.loadUrl("http://192.168.1.2");
          //_Layout.getViewTreeObserver().removeGlobalOnLayoutListener(this); 
      }
  }
  </code></pre>
  
  <p>If I comment removeGlobalOnLayoutListener() out, it stops working. Debugger shows it's called twice, so I guess the second call only actually sets the size. So, I've decided not to remove the listener (if it's called 2 times, that's not a performance killer). It'd seemed OK, until I realized it's called whenever I click a permanent bottom-bar, causing toolbar appearance. And since I load a site after setting layout, it's being reloaded every time. And I have to load the site only when the view' size is correct, because a server sends content, specially optimized for the given size.</p>
  
  <p>That's why I cannot leave the listener and should remove it. But when? Just count to 2? Will it work on every device/Android version? Why does it work for the second call, but not for the first?</p>
  
  <p>Regards,</p>