Why isn't my WebView filling up the entire width of my screen?

13,351

Solution 1

The linear layout is orientation horizontal I don't think you can fill width on orientation horizontal.

Try using RelativeLayout instead. (just rename LinearLayout to RelativeLayout)

Solution 2

That size is being taken up by the webview's scroll bar. use this to get rid of it

browser.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);

Solution 3

In Activity layout (xml) and more specifically LinearLayout Tag contains some padding by default like: android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin"

Delete that, set your WebView to fill_parent and then it will do the job.

Share:
13,351
Sheehan Alam
Author by

Sheehan Alam

iOS, Android and Mac Developer. i can divide by zero.

Updated on July 31, 2022

Comments

  • Sheehan Alam
    Sheehan Alam almost 2 years

    My WebView doesn't fill the entire width of my phone. I am telling to fill_parent. Not sure why?

    <?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"
            android:orientation="horizontal">
    
        <WebView android:layout_height="fill_parent" android:layout_width="fill_parent" android:id="@+id/WebView"></WebView>
        </LinearLayout>
    
  • tvieira
    tvieira almost 10 years
    if didn't solve the issue, why it's marked as the correct answer?