2013-01-16 76 views
0

如何使一个Webview是-10dp宽度,并与背景图像父布局的高度看起来像下面的图片:如何使webview是-10dp父级布局的宽度和高度?

更新: 蓝盒子是屏幕。 黑色框是外部布局(@ + id/wrapper),红色框是webview(@ + id/webview) 绿色框是一些其他布局。

demo

我试图用下面的代码,但没有成功。 如果webview中的内容太长,则外部布局会拉伸。我想要一个固定大小的webview内的布局,但我不知道如何实现这一点。

Ps。黑匣子的背景图像不是全屏。

会有人给我一些提示吗?

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

刚刚更新的android:layout_height = “match_parent” 成XML文件 –

回答

0

使用此代码,而不是

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

+0

我已经更新了我的问题,请参见图像。黑匣子的背景图像不是全屏。 – Hanon

+0

@Hanon检查我的更新的答案,如果它仍然工作,那么请提供您的XML的完整源代码,并请停止将您的意见作为黑盒,绿框,红框等,它非常混乱。而是使用每个视图的ID。 – Antrromet

0

使用

机器人:填充= “10dip” 到网页视图的父。

0

使用此代码,而不是

它看起来像如图图像 enter image description here

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

我已更新我的问题,请参阅图片。黑匣子的背景图像不是全屏。 – Hanon

0

未经测试,但你可以试试这个:

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

试试这个:

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

我已更新我的问题,请参阅图片。黑匣子的背景图像不是全屏。我试过这个解决方案,但它仍然伸展。 – Hanon

相关问题