2013-01-16 74 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

相關問題