简体   繁体   English

如何使WebView的父布局的宽度和高度为-10dp?

[英]How to make a webview is -10dp width and height of the parent layout?

How to make a webview is -10dp width and height of the parent layout with a background image look like the following image: 如何使Webview的父布局的宽度和高度为-10dp,并带有背景图片,如下图所示:

Updated: The blue box is the screen. 更新:蓝色框是屏幕。 The black box is the outer layout(@+id/wrapper) and the red box is the webview(@+id/webview) The green box is some other layout. 黑框是外部布局(@ + id / wrapper),红色框是webview(@ + id / webview),绿色框是其他布局。

演示

I have tried with the following code but have no success. 我尝试使用以下代码,但没有成功。 If the content in the webview is too long, the outer layout will stretch. 如果Web视图中的内容太长,则外部布局将拉伸。 I want a fixed size webview inside the layout but I don't know how to achieve this. 我想在布局内放置一个固定大小的Webview,但我不知道该如何实现。

Ps. 附言 The background image of the black box is not full screen. 黑匣子的背景图像不是全屏。

Would somebody give me some hints? 有人能给我一些提示吗?

<?xml version="1.0" encoding="utf-8"?>
<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"
    android:background="@drawable/common_background" >

    ... some other layout ...

    <LinearLayout
        android:id="@+id/wrapper"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:background="@drawable/wrapper_background" >

        <WebView
            android:id="@+id/webview"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="10dp" />
    </LinearLayout>

    ... some other layout ...

</RelativeLayout>

Use this code instead 改用此代码

<LinearLayout
    android:id="@+id/wrapper"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_above="@+id/someOtherLayout"
    android:layout_centerInParent="true"
    android:background="@drawable/wrapper_background" >

    <WebView
        android:id="@+id/webview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="10dp" />
</LinearLayout>

<Some Other Layout
    android:id="@+id/someOtherLayout"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true" />

use 采用

android:padding="10dip" to the parent of webview. android:padding =“ 10dip”到webview的父级。

Use this code instead 改用此代码

it will look like As shown in image 它看起来像如图所示 在此处输入图片说明

xml Code: xml代码:

<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"
    android:background="@drawable/ic_launcher" >


  ... some other layout ...
    <LinearLayout
        android:id="@+id/wrapper"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_centerInParent="true"
        android:background="@drawable/ic_launcher" >

        <WebView
            android:id="@+id/webview"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="10dp" />
    </LinearLayout>
  ... some other layout ...


</RelativeLayout> 

Not tested but you can try this: 未经测试,但是您可以尝试以下方法:

<LinearLayout
        android:id="@+id/wrapper"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:padding="10dp"
        android:background="@drawable/wrapper_background" >

Try out this: 试试这个:

  <?xml version="1.0" encoding="utf-8"?> <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" android:background="@drawable/common_background" > ... some other layout ... <LinearLayout android:id="@+id/wrapper" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_centerInParent="true" android:padding="10dip" <---- Apply this in your layout. android:background="@drawable/wrapper_background" > <WebView android:id="@+id/webview" android:layout_width="match_parent" android:layout_height="match_parent" /> </LinearLayout> ... some other layout ... </RelativeLayout> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM