android - 如何在 WebView 周围添加填充

标签 android android-layout android-webview padding

我的布局文件定义了一个WebView,下面有一些固定高度的按钮。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:fadingEdge="none">

  <WebView
    android:id="@+id/webview"
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_weight="1.0"/>

  <LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="60dp"
    android:padding="8dp">

    <Button
      android:text="Decline"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_weight="1.0">
    </Button>

    <Button
      android:text="Accept"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_weight="1.0">
    </Button>

  </LinearLayout>
</LinearLayout>

我正在尝试在 WebView 周围添加填充,因为目前文本一直延伸到 UI 的边缘。

我尝试将 android:padding="8dp" 添加到 WebView,但没有添加任何填充。我也尝试了 paddingLeft 和 paddingRight,但它们也不起作用。

WebView API 文档确认它继承自 View,后者支持 android:padding属性,所以我很惊讶这不起作用。

有人知道这是一个已知问题,还是我不理解的布局 XML 的某些交互?

仅供引用,我的解决方法是在 WebView 周围放置一个额外的 LinearLayout,然后添加填充:

  <LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_weight="1.0"
    android:padding="8dp">

    <WebView
      android:id="@+id/webview"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"/>

  </LinearLayout>

最佳答案

WebView 在填充实现中存在错误。在 webview 上设置填充不会填充实际的网页,但会填充滚动条。它只是部分按预期工作。 您的解决方案是为 WebView 实现“填充”的最佳方式。

关于android - 如何在 WebView 周围添加填充,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9170042/

相关文章:

android - notifyDataSetChanged() 在 daimajia AndroidSwipeLayout 中不起作用

java - Android - 使用纯 Java 和无 XML 创建应用程序?

android - 使用单击事件以编程方式在android中创建按钮

java - 从抽屉菜单中加载 webview 中的本地 HTTP 文件?

javascript - 禁用缓存、cookie 和 WebView 中的所有其他内容

java - Android在更新后仍然坏了

android - 从相机和画廊获取照片

android - runOnUiThread 如何在不影响现有 UI 线程的情况下在以下代码中工作

java - 如何在 Android Studio 中检查字符串是否为空或 null

Android Scroll Webview 可编辑到光标 - 软键盘