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

北战南征 提交于 2020-01-01 10:44:29

问题


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>

回答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)




回答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);



回答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.




回答4:


I know in my xml you will fill the width up with no issues... check it out.

you will see i am using the wrap_content in my base LinearLayout

   <LinearLayout android:orientation="horizontal"  android:background="@drawable/dailygoal"
        android:layout_height="wrap_content" android:layout_width="fill_parent"
       android:padding="3px"

      >         
            <WebView
        android:id="@+id/dailygoalswebview"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
         android:layout_gravity="right"
         android:padding="20px" 
        >
    </WebView>
             </LinearLayout>

I just applied the above xml to my main.xml layout... i hope you the best of luck..




回答5:


In Activity layout (xml) either it may be relative or other layout it 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 the above lines, and fill the width and height to be "fill_parent". this works



来源:https://stackoverflow.com/questions/3859502/why-isnt-my-webview-filling-up-the-entire-width-of-my-screen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!