我的布局文件定义了一个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/