Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7969025
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:10:18+00:00 2026-06-04T07:10:18+00:00

I need an activity to load an HTML document into a WebView, but for

  • 0

I need an activity to load an HTML document into a WebView, but for the WebView to then be resized so it tightly wraps the HTML document. e.g. if the HTML document contains a single div which is 300×200 pixels in size, I’d want the WebView to resize to be 300px x 200px to exactly contain the document.

Vertically WebView behaves this way naturally. The height of a WebView (with wrap_content) is determined by the height of the HTML document, but oddly not the width which always fills the width (unless a dimension is specified for the width). i.e. as far as I can see using layout_width=”wrap_content” with a WebView doesn’t work.

Is there a way to configure WebView to resize its width in this way? I cannot see one. If the HTML content is thinner than the screen width, I want the WebView to be thinner.

If not, is there a way to acquire absolute element sizes post-rendering in the HTML document model, which I can then use to resize the WebView width?

To demonstrate, here’s the statement to load static content into the WebView:

browser.loadDataWithBaseURL("/", "Hello!", "text/html", "utf-8", null);

And here’s the simple layout

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <WebView
        android:id="@+id/webview"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:visibility="visible"
        />
</LinearLayout>

I’d expect this to show a WebView to the upper left extending part way across the width, but instead it extends all the way across the whole width of the screen (despite wrap_content, and the content being smaller than the width)

enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T07:10:19+00:00Added an answer on June 4, 2026 at 7:10 am

    I think, you might use android:layout_marginRight=200px feature of WebView in your layout xml.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my activity, I create a Bitmap object and then I need to launch
I have one SubjectTabActivity and i need to show listview on this activity. But
In my Android Activity, I need to add a single View dynamically (at runtime),
i have a html file and i have to load html content into my
I have Activity with some data displayed in WebView that I load with WebView#loadDataWithBaseURL
I'm trying to load the main activity of another app into my own view
I need to load a text file which is placed in res/raw directory into
I've been trying to load a bitmap in a non-activity class but everything I've
I need to re-launch an activity to re-load a static library. If I want
I've got some Asynchronous cleanup activity I need to do as my Qt application

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.