【问题标题】:Can't scroll webview in Android无法在 Android 中滚动 webview
【发布时间】:2012-05-11 13:51:11
【问题描述】:

我的 WebView 出现了一些奇怪的问题。问题是如果页面比屏幕长,我无法在 Android 2.2 和 2.3 中滚动页面。滚动 WebView 的唯一方法是在 Android 4.0.3 中。是什么问题,或者在低于 4.0.3 的 Android 版本中无法滚动 WebView?

这是我的布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
    android:layout_width="fill_parent" android:id="@+id/rltvLayout01"
    android:layout_height="fill_parent" android:background="@color/white">  
    <LinearLayout android:id="@+id/LinearLayout01"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_above="@+id/ad_layout">
            <WebView android:id="@+id/webview"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:fitsSystemWindows="true"
                android:scrollbars="none" />
    </LinearLayout>
    <LinearLayout android:id="@+id/ad_layout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true">
            <com.google.ads.AdView android:id="@+id/ad"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                ads:adUnitId="-------------"
                ads:loadAdOnCreate="true"
                ads:adSize="BANNER" />
    </LinearLayout>
</RelativeLayout>

编辑 23:06:

我刚刚发现了问题!我使用的实际代码不会导致这种行为,而是加载的网站导致了问题。在我的移动网站中,我使用视口来正确显示它,而 FroYo 和 Gingerbread 的 WebView 不能很好地处理它。因此,在删除视口元标记后,它可以完美运行!无论如何感谢 Thomas K,垂直方向在移除视口后也可以滚动!

如果你想让你的 webview 在 Froyo 和 Gingerbread 中工作,请去掉 html 代码中的 viewport 标签!

【问题讨论】:

    标签: android webview


    【解决方案1】:

    添加

    android:orientation="vertical"
    

    android:orientation="horizontal"
    

    到线性布局

    【讨论】:

    • 由于某种原因我仍然无法滚动:(
    • 它是否可能与 relativelayout 或其他什么有关?甚至可能是项目中的其他代码?据我所知,我没有触及垂直滚动......
    • 您可以尝试使布局更简单。 (只有一个linearLayout和webview)。您是否尝试将您的 webview 设置为“fill_parent”的高度?
    • 是的,我也试过了。我还尝试使布局只有一个线性且只有 webview。但即便如此,我也无法滚动。这真的很奇怪:(
    • 我也发布了我的其他来源,所以问题可能出在其他地方!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-09
    • 1970-01-01
    • 2012-11-07
    • 2012-11-07
    相关资源
    最近更新 更多