2009-11-05 55 views
4

所以我有一個webview我想顯示爲對話框。我希望webview能夠填充整個屏幕,除了下面的一個按鈕,我希望停留在對話框的底部,而不管webview中有多少內容。目前,我的webview填充對話框足以將按鈕從屏幕上移開。我確信這是非常簡單的事情,但對於我來說,我一直無法找到佈局,視圖和屬性值的神奇組合,以使它發揮出色。只是要清楚,我已經得到它,所以按鈕漂浮在web視圖上,但我希望webview停止在按鈕上方並滾動,如果這是有道理的。Android佈局問題與下面的按鈕WebView

<RelativeLayout android:id="@+id/RelativeLayout01" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       xmlns:android="http://schemas.android.com/apk/res/android"> 
    <WebView android:id="@+id/webview" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      /> 
    <Button android:text="Ok" 
      android:id="@+id/btnOk" 
      android:layout_width="120px" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_horizontal" 
      android:layout_alignParentBottom="true" 
      /> 
</RelativeLayout> 

回答

7

您將要使用Android:layout_above = 「@ + ID/btnOk」 爲您的WebView,併爲web視圖的寬度和高度做FILL_PARENT。

但是,需要注意的是,在1.5和更低版本中,需要按照順序指定RelativeLayout視圖,才能正確識別xml。換句話說,必須首先使用Button,然後使用WebView ,因爲WebView將引用該按鈕。我認爲這已經改變了1.6或2.0,但我並不積極哪一個。

<RelativeLayout android:id="@+id/RelativeLayout01" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       xmlns:android="http://schemas.android.com/apk/res/android"> 

    <Button android:text="Ok" 
      android:id="@+id/btnOk" 
      android:layout_width="120px" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_horizontal" 
      android:layout_alignParentBottom="true" 
      android:layout_centerHorizontal="true"/> 
    <WebView android:id="@+id/webview" 
      android:layout_above="@+id/btnOk" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      /> 
</RelativeLayout> 
+0

你先生,是我最喜歡的人。即使經過數月的Android開發,我仍然在學習一些基本的東西。你有我的感激之情! – MattC 2009-11-05 04:25:50

+0

它是修復前向參考問題的1.6: http://android-developers.blogspot.com/2009/10/ui-framework-changes-in-android-16.html – I82Much 2009-11-05 15:03:51