【问题标题】:Scroll view doesn't resize when the content of child view changes当子视图的内容发生变化时,滚动视图不会调整大小
【发布时间】:2010-08-18 05:16:11
【问题描述】:

我在ScrollView 中有一个WebView

WebView 的内容在显示不同的 html 页面时会动态变化。

我有以下问题:

例如,我有A.htmlB.htmlB.html的内容比A.html大,所以页面比较长。

WebView 加载B.html 时,ScrollView 会拉伸其大小以使自己能够滚动 B.html,然后如果我回到 A.html,则 ScrollView 不会自行调整大小。 (滚动区域超出A.html的内容)

我想要的是动态更改滚动视图的滚动区域以适应 webview 的内容。

【问题讨论】:

    标签: android webview scrollview


    【解决方案1】:

    尝试在滚动视图中使用android:fillViewport..!!

    <ScrollView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/scroller"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:fillViewport="true" >
    

    【讨论】:

      【解决方案2】:

      方向屏幕调整大小后,它可以工作但性能不佳,不是一个很好的解决方案

      setRequestedOrientation( ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE );
      setRequestedOrientation( ActivityInfo.SCREEN_ORIENTATION_SENSOR );
      

      【讨论】:

        【解决方案3】:

        这对我有帮助:

        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fillViewport="true">
            
            <WebView
               android:id="@+id/webView"
               android:layout_width="match_parent"
               android:layout_height="wrap_content" />
        
        </ScrollView>
        
        

        【讨论】:

          【解决方案4】:

          将 WebView 放在 ScrollView 中并不是一个好主意。 WebView 足够聪明,可以自己显示滚动条。

          【讨论】:

          • 如果我们想要滚动的 WebView 上方有内容怎么办?有没有办法让 ScrollView 重新评估?
          • 我想知道为什么这个答案被接受,问题是“如何?”而不是“这是个好主意吗?”
          • 但他是对的(在大多数情况下)。如果问题的作者决定标记答案,他/她可能知道在做什么。我想知道为什么它不好......
          【解决方案5】:

          不要将WebView 放在ScrollView 中。

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 2013-07-28
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2016-01-06
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多