【问题标题】:Unable to give margin or padding for webview in frame layout无法在框架布局中为 webview 提供边距或填充
【发布时间】:2012-10-13 03:57:45
【问题描述】:

这是我的代码。我无法在线性布局下方准确对齐 webview

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

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

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="50dip"
    android:orientation="horizontal" >

    <EditText
        android:id="@+id/etenterurl"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:layout_weight="1.0"
        android:inputType="textUri" />

    <Button
        android:id="@+id/buttongo"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="3.0"
        android:text="Go" />
</LinearLayout>

</FrameLayout>

【问题讨论】:

  • schemas.android.com/apk/res/android" android:id="@+id/mapView" android:layout_width="fill_parent" android:layout_height=" fill_parent" android:clickable="true" android:apiKey="0qr-V5OUQ5OFt9C3sDkwhiGpPbxsdUvfBVFx8pA" />

标签: android webview


【解决方案1】:

WebView 实现中存在错误,填充无法正常工作,

有关解决方法,请参阅:How to add padding around a WebView

但我认为这是您正在寻找的:

RelativeLayout 轻松解决了这个问题!仔细查看 layout_below 给 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" >

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

    <LinearLayout
        android:id="@+id/bar"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <EditText
            android:id="@+id/etenterurl"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_weight="1.0"
            android:inputType="textUri" />

        <Button
            android:id="@+id/buttongo"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="3.0"
            android:text="Go" />
    </LinearLayout>

</RelativeLayout>

【讨论】:

    【解决方案2】:

    为什么不将您的 FrameLayout 更改为 RelativeLayout 然后使用

    <LinearLayout
        android:id="@+id/bar"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >
    
        ...
    
    </LinearLayout>
    
    <WebView
        android:id="@+id/webview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_below="@+id/bar"
        android:layout_below="@id/bar" />
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-02-28
      • 2012-06-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-27
      • 1970-01-01
      相关资源
      最近更新 更多