简体   繁体   中英

How to fit webview to full screen?

I want to my webview to fit the screen ,now there is a small empty border along the webview (not coming full screen). how to make my webview to fit screen by using xml code在此处输入图片说明

  <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  tools:context="com.fb.jaisonjoseph.facebookbasic.Home_Fragment">

  <!-- TODO: Update blank fragment layout -->


  <WebView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/webView"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true"
    android:layout_alignParentTop="true"
    android:layout_alignParentBottom="true" />
    </RelativeLayout>

You simply add this in your parent layout:

<WebView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/webView" />

The problem that you are having is most likely because your activity_main probably still has the preset padding that is put in when you first create an Application. This is a code example I made and it worked on full Screen:

主活动.java

活动_main.xml

Replace your WebView code with this one

<WebView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/webView"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true"
    android:layout_alignParentTop="true"
    android:layout_alignParentBottom="true"
    android:layout_margin="0dp"
    android:padding="0dp"/>

I think this code change works for you

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
ndroid:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingBottom="0dp"
android:paddingLeft="0dp"
android:paddingRight="0dp"
android:paddingTop="0dp"
tools:context=".MainActivity" >

in xml file, change activity padding to "0dp" and change webview to fill_parent or match_parent.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM