2011-10-10 132 views
1

如果我的WebView太大,我沒問題,即使內容太大,WebView高度也適合屏幕高度,我可以滾動WebView的內容。 但是,如果WebView的內容很少,則WebView高度不適合屏幕。如何使WebView高度尺寸與屏幕高度吻合?

這是我的佈局:

<?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="wrap_content" > 

<ScrollView android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
     android:fitsSystemWindows="true"> 

    <WebView android:id="@+id/webview" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:fitsSystemWindows="true" /> 

</ScrollView> 

<LinearLayout android:id="@+id/media_player" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:visibility="visible"> 

    <Button android:textStyle="bold" 
     android:id="@+id/ButtonPlayStop" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:background="@android:drawable/ic_media_play" /> 

    <SeekBar android:id="@+id/SeekBar" 
     android:layout_height="wrap_content" 
     android:layout_width="fill_parent" 
     android:layout_below="@id/ButtonPlayStop" /> 

</LinearLayout> 

下面是截圖:

enter image description here

任何一個可以幫助我解決這個問題?

回答

8

您不需要在ScrollView的內部放置WebView,因爲它的內容大於其視圖邊界時,它已經知道如何滾動。在其他滾動視圖內放置滾動視圖往往會導致不良行爲。

無視這一秒,如果ScrollView的內容太小,它不會自己伸展以佔用額外的空白空間。也就是說,除非使用特殊標誌(android:fillViewport)。

作爲解決方案,我將刪除外部的ScrollView並嘗試使WebView佔據自己的空間。如果使用RelativeLayout作爲容器,你可以只用一個級別的深度獲取此佈局:

  • 播放按鈕進入左下角父母
  • 搜索欄轉到底部的發揮正確的按鈕
  • 的WebView高於他們fill_parent在寬度和高度

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    
    <Button android:textStyle="bold" 
    android:id="@+id/ButtonPlayStop" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:background="@android:drawable/ic_media_play" /> 
    
    <SeekBar android:id="@+id/SeekBar" 
    android:layout_toRightOf="@+id/ButtonPlayStop" 
    android:layout_alignParentBottom="true" 
    android:layout_height="wrap_content" 
    android:layout_width="fill_parent" 
    android:layout_below="@id/ButtonPlayStop" /> 
    
    <WebView android:id="@+id/webview" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_above="@id/ButtonPlayStop" /> 
    
    </RelativeLayout> 
    
+0

你的答案是非常大的。謝謝你的幫助。我瞭解到我需要更多地使用RealativeLayout http://developer.android.com/reference/android/widget/RelativeLayout.LayoutParams.html –