I am a beginner in Android and building a linear layout
and getting an error in the layout XML file like this,
Error
Placi
I had the same issue before, I had to set the height to 250dp, but I couldn't, so what I did was just wrap it into a FrameLayout and set the custom height to it, you can set the height you want to the wrapper (just not wrap_content
) and it will work with no problem:
<FrameLayout
android:layout_width="match_parent"
android:layout_height="250dp">
<WebView
android:id="@+id/web_view_tutorial"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</FrameLayout>
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.
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:
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.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();
}
}