Error: Android-XML:Placing a <WebView> in a parent element that uses a wrap_content size can lead to subtle bugs; use match_parent

Contrary to what most answers imply, this is not a bug in Eclipse resp. Android Studio, but a fair warning. It's produced by a LINT check on your layout.

You can remove the warning and work around the 'subtile bugs' like so:

  1. Add tools:ignore="WebViewLayout" to your WebView (thanks to @StefanDeitmar) and make the tools namespace known by adding xmlns:tools="http://schemas.android.com/tools" to your outmost layout element.
  2. In your code, add a WebViewClient to your WebView and implement the OnPageFinished() callback to invoke a requestLayout() on your wrapping layout element.
mWebView.setWebViewClient(new WebViewClient() {
    @Override
    public void onPageFinished(WebView webView, String url) {
        super.onPageFinished(webView, url);
        mSurroundingLayout.requestLayout();
    }
}

The issue is mainly because in the parent LinearLayout, you have provide layout_width and layout_height as wrap_content. It should be match_parent.

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" 
    android:layout_height="match_parent"
    android:orientation="vertical" >

Actually I think that this is a bug in Eclipse, or the latest version 20 Android SDK.

I have screen designs that are made up of stacked web views because their contents come from different sources. My screen layouts "wrap content" for height so that the user always sees what information is returned from the various sources without vast areas of blank. Its an unusual design, but one that has worked well for 4+ years on many similar applications. Yup, I know that I have to be careful about heights, etc, but I'm happy to take on that responsibility.

Eclipse is essentially creating a "Nanny State" - that's not the way we normally do it so its wrong. Pardon me but I differ in opinion.

The way I got around this was to close the XML file and completely clean the project. This way Eclipse forgets that it ever "nanny nagged" about this issue and everything is good again.