14

I have a WebView inside the ScrollView.

The content of WebView dyanamically changes when it displays different html page.

I have the following issue:

For example I have A.html, and B.html. The content of B.html is larger than A.html, so the page is longer.

When WebView load B.html, the ScrollView stretches its size to enable itself scroll for B.html, then if I go back to A.html, ScrollView doesn't resize itself. (The scroll area is exceed the content of A.html)

alt text

What I want to have, is dynamic change the scroll area of scroll view to fit the webview's content.

DAIRAV
  • 723
  • 1
  • 9
  • 31
TS.xy
  • 1,244
  • 2
  • 13
  • 29

5 Answers5

5

Try using android:fillViewport in scroll view..!!

<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" >
Adrian Grygutis
  • 470
  • 1
  • 8
  • 18
Eby
  • 2,769
  • 4
  • 23
  • 30
1

After Orientation screen will resize, it works but bad in performance, not a very good solution

setRequestedOrientation( ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE );
setRequestedOrientation( ActivityInfo.SCREEN_ORIENTATION_SENSOR );
kamaci
  • 72,915
  • 69
  • 228
  • 366
zap
  • 191
  • 3
  • 8
0

This helped me:

<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>

Hawklike
  • 952
  • 16
  • 23
-3

That's not good idea to place WebView inside of ScrollView. WebView is smart enough to show scrollbars by itself.

Konstantin Burov
  • 68,980
  • 16
  • 115
  • 93
  • 7
    What if we have content above the WebView that we want to scroll as well? Is there a way to cause the ScrollView to re-evaluate? – Steven Sep 03 '13 at 18:59
  • 3
    I wonder why this answer is accepted, the question was "How?" rather than "Is it good idea?" – Yuriy Jun 02 '16 at 15:03
  • But he's right (in most cases). If author of question decides to mark answer, he/she probably knows what doing. I wonder why it' bad... – Adrian Grygutis Feb 12 '18 at 11:09
-7

Don't put a WebView inside of a ScrollView.

Rich Schuler
  • 41,814
  • 6
  • 72
  • 59