【发布时间】:2012-02-28 12:20:22
【问题描述】:
我的布局文件定义了一个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 imo 来说真的没有意义
-
好主意,但是我只是尝试在我的原始 XML 中的 WebView 上设置 layout_marginRight 和 layout_marginLeft,结果导致下面的按钮不显示。我想知道为什么我的布局有什么根本错误?
-
看起来您的 layout_weight 设置不正确。如果按钮是 wrap_content,为什么要给按钮 layout_weight?
-
@DanJ 我告诉你,android 设计师有一些根本性的问题
标签: android android-layout android-webview padding