如何添加填充周围的WebView [英] How to add padding around a WebView

查看:166
本文介绍了如何添加填充周围的WebView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的布局文件中定义了一个web视图,其下有一些固定高度的按钮。

 < XML版本=1.0编码=UTF-8&GT?;
<的LinearLayout
  的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
  机器人:方向=垂直
  机器人:layout_width =FILL_PARENT
  机器人:layout_height =FILL_PARENT
  机器人:fadingEdge =无>

  <的WebView
    机器人:ID =@ + ID / web视图
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =0dp
    机器人:layout_weight =1.0/>

  <的LinearLayout
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =60dp
    机器人:填充=8DP>

    <按钮
      机器人:文本=拒绝
      机器人:layout_width =WRAP_CONTENT
      机器人:layout_height =WRAP_CONTENT
      机器人:layout_weight =1.0>
    < /按钮>

    <按钮
      机器人:文本=接受
      机器人:layout_width =WRAP_CONTENT
      机器人:layout_height =WRAP_CONTENT
      机器人:layout_weight =1.0>
    < /按钮>

  < / LinearLayout中>
< / LinearLayout中>
 

我想添加填充周围的WebView,因为此刻的文本运行直到用户界面的边缘。

我尝试添加安卓填充=8DP的web视图,但不会添加填充。我也尝试以下属性来和paddingRight过,但他们也不能工作。

借助的WebView API文档确认从View,它支持的<一个继承href="http://developer.android.com/reference/android/view/View.html#attr_android%3apadding">android:padding属性,所以我很惊讶这没有奏效。

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

仅供参考,我的解决方法是把一个额外的LinearLayout各地的WebView,并填充添加到代替:

 &LT;的LinearLayout
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =0dp
    机器人:layout_weight =1.0
    机器人:填充=8DP&GT;

    &LT;的WebView
      机器人:ID =@ + ID / web视图
      机器人:layout_width =FILL_PARENT
      机器人:layout_height =FILL_PARENT/&GT;

  &LT; / LinearLayout中&GT;
 

解决方案

web视图在填充实现中的错误。在web视图不会垫的实际网页,但会垫滚动条设置填充。这只是部分工作正常。 您的解决方案是实现填充了的WebView的最佳方式。

My layout file defines a WebView, underneath which there are some fixed height buttons.

<?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>

I'm trying to add padding around the WebView, as at the moment the text runs right up to the edge of the UI.

I tried adding android:padding="8dp" to the WebView, but no padding was added. I also tried paddingLeft and paddingRight too, but they didn't work either.

The WebView API docs confirm it inherits from View, which supports the android:padding attribute, so I'm surprised this didn't work.

Does anybody know if this is a known issue, or some interaction of my layout XML that I'm not understanding?

FYI, my workaround was to put an extra LinearLayout around the WebView, and add the padding to that instead:

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

解决方案

The WebView has a bug in the padding implementation. Setting a padding on a webview won't pad the actual web page, but WILL pad the scrollbars. It's only partially working as expected. Your solution is the best way to achieve 'padding' for a WebView.

这篇关于如何添加填充周围的WebView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆