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

后端 未结 4 1332
夕颜
夕颜 2021-02-13 13:20

I am a beginner in Android and building a linear layout and getting an error in the layout XML file like this,

Error

 Placi         


        
4条回答
  •  青春惊慌失措
    2021-02-13 14:06

    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();
        }
    }
    

提交回复
热议问题