【问题标题】:How to fit webview to full screen?如何使 webview 适合全屏?
【发布时间】:2017-01-16 04:03:13
【问题描述】:

我想让我的 webview 适合屏幕,现在沿 webview 有一个小的空白边框(不是全屏显示)。如何使用 xml 代码

使我的 webview 适合屏幕
  <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>

【问题讨论】:

  • 我认为你已经使用了片段。因此,请尝试检查活动 xml 中的填充或边距。
  • 尝试使用 webview 的 layout_weight & height match_parent ...也将你的 main_activity .XML 文件放入
  • 我也试过@SagarAghara
  • 是的...然后在您的 activity_main 中删除边距或填充,这将解决您的问题..@DheerubhaiBansal 已经告知
  • 是的 100% 在你的 activity_main 16dp 中填充,检查一下。

标签: android webview


【解决方案1】:

您只需将其添加到您的父布局中:

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

【讨论】:

    【解决方案2】:

    您遇到的问题很可能是因为您的 activity_main 可能仍然具有在您首次创建应用程序时放入的预设填充。这是我制作的代码示例,它可以在全屏上运行:

    【讨论】:

      【解决方案3】:

      用这个替换你的 WebView 代码

      <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"/>
      

      我认为此代码更改对您有用

      【讨论】:

        【解决方案4】:
        <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" >
        

        在 xml 文件中,将活动填充更改为“0dp” 并将 webview 更改为 fill_parent 或 match_parent。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2020-11-10
          • 1970-01-01
          • 1970-01-01
          • 2017-06-15
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多