Skip to content Skip to sidebar Skip to footer

How Add A Webview To A Layout That Have More Widgets

I want to add a webview to my layout.But that layout have few other widgets also.But when i run the application webview takes the entire screen and other widgets get disappear.here

Solution 1:

Try to set the WebViewClient, it will solve your problem.

/** Called when the activity is first created. */@OverridepublicvoidonCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

         WebView wv1=(WebView)findViewById(R.id.web1);
         wv1.setWebViewClient(newmyClient());
         wv1.loadUrl("http://google.com");
    }

    classmyClientextendsWebViewClient
    {
        @OverridepublicvoidonPageFinished(WebView view, String url) {
            // TODO Auto-generated method stubsuper.onPageFinished(view, url);
        }

        @OverridepublicbooleanshouldOverrideUrlLoading(WebView view, String url) {
            // TODO Auto-generated method stub

            view.loadUrl(url);
            returntrue;
        }

        @OverridepublicvoidonReceivedError(WebView view, int errorCode,
                String description, String failingUrl) {
            // TODO Auto-generated method stubsuper.onReceivedError(view, errorCode, description, failingUrl);
        }
    }

Solution 2:

change your xml like this, then your textview vill be shown on the botton, the view will be shown above the textview, the webview will be shown in the rest spase.

<RelativeLayout...
><TextViewandroid:layout_alignParentBottom="true"android:id="@+id/sample_text"...
/><Viewandroid:layout_above="@id/sample_text"android:id="@+id/sample_view"...
><WebViewandroid:layout_above="@id/sample_view"...
/></RelativeLayout>

Post a Comment for "How Add A Webview To A Layout That Have More Widgets"