1

如果我的 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>

这是屏幕截图:

在此处输入图像描述

任何人都可以帮助我解决这个问题?

4

1 回答 1

8

您不需要将 aWebView放在内部,ScrollView因为它已经知道当其内容大于其视图边界时如何滚动。将滚动视图放在其他滚动视图中往往会导致不良行为。

ScrollView暂时不考虑,如果内容太小,a将不会伸展自己以占用额外的空白空间。也就是说,除非使用特殊标志(android:fillViewport)。

作为一种解决方案,我会移除外部ScrollView并尝试WebView让其自行占据空间。如果你使用 aRelativeLayout作为容器,你可以获得这个只有一层深度的布局:

  • 播放按钮位于父级的左下角
  • 搜索栏位于播放按钮的底部和右侧
  • 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>
    
于 2011-10-10T20:10:42.860 回答