【问题标题】:Android: problem scrolling my activity including a WebViewAndroid:滚动我的活动(包括 WebView)时出现问题
【发布时间】:2010-11-12 19:11:32
【问题描述】:

我在我的活动中包含了一个 WebView,并在其中加载了一些 Javascript,然后将从外部网站获取数据。 这可以正常工作并且显示正常,但问题是当 WebView 完成加载时我的活动不会滚动,所以我看不到 WebView 的底部,例如我放在它下面的所有其他视图。知道我应该如何处理吗? 干杯。

【问题讨论】:

    标签: android webview


    【解决方案1】:

    您是否在布局中使用滚动视图?试试看是否有帮助。

    这里是开发者page的链接

    【讨论】:

    • 您不能将ScrollView 与WebView 一起使用,AFAIK。 ScrollView 不适用于其他本质上知道如何滚动的小部件。
    • 你是对的,我忘了你用的是webview。那么听起来你可能有一个布局问题,你可能会错误地填写内容。就像commonsware提出的建议。
    • 我实际上刚刚读完一篇关于 scrollview 与 webview 的一些技巧的文章,正要对此发表评论,很高兴听到你让它工作了。
    【解决方案2】:

    这可以正常工作并且显示良好,但问题是当 WebView 完成加载时我的活动没有滚动,所以我看不到 WebView 的底部,例如我放在它下面的所有其他视图。

    您需要更改布局,以便“我在此下方放置的其他视图”将显示在屏幕上,而 WebView 只需占用剩余空间。

    例如,这是一个显示WebView 和Button 的布局:

    <?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="fill_parent"
        >
        <WebView android:id="@+id/webkit"
                android:layout_width="fill_parent" 
            android:layout_height="0px"
            android:layout_weight="1"
        />
        <Button android:id="@+id/helpcast"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="View Helpcast"
        />
    </LinearLayout>
    

    因为WebView 设置了0px 高度但重量为1,并且因为Button 未指定重量,所以WebView 将填充Button 之后剩余的所有空间在屏幕上。如果需要,WebView 内容将在 WebView 内部滚动,具体取决于您在其中加载的任何网页。

    【讨论】:

    • 感谢您的回答,我设法使用 ScrollView 做我想做的事。但是我无法使用 android:layout_height="0px" android:layout_weight="1" 获得任何滚动
    猜你喜欢
    • 1970-01-01
    • 2013-02-28
    • 2019-03-05
    • 2011-12-12
    • 1970-01-01
    • 2015-11-04
    • 1970-01-01
    • 2017-05-17
    • 1970-01-01
    相关资源
    最近更新 更多