2011-10-10 134 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 –