Skip to content Skip to sidebar Skip to footer

How Do I Resize My Webview In Activity?

My XML File WebView Can Anybody tell me what is t

Solution 1:

i think there is that you should look these two questions

WebView doesn't resize

but from that i see you need to create new WebView every time

WebView height = wrap_content with changing font size doesn't work

And the answers too...

EDIT for creating new webview programmatically

Webview in programmatically created RelativeLayout

and this also Im trying to programmatically insert a WebView into my Code

Solution 2:

You should create WebView in your code instead of updating it's content. Follow the steps:

  1. Replace your WebView tag in your layout file with following:

    <FrameLayout
    android:id="@+id/webViewContainer"android:layout_width="match_parent"android:layout_height="wrap_content" >
    </FrameLayout>
    
  2. Do following in your Activity class code:

    if (webView!= null) {
     webViewContainer.removeAllViews();
     webView.destroy();
    }
    webView= new WebView(context);
    webViewContainer.addView(webView,
                new FrameLayout.LayoutParams(
                        FrameLayout.LayoutParams.MATCH_PARENT,
                        FrameLayout.LayoutParams.WRAP_CONTENT));
    webView.loadDataWithBaseURL(null, myHtmlString, "text/html",
                    "UTF-8", null);
    

Post a Comment for "How Do I Resize My Webview In Activity?"