Question

I have this layout, and it's scaled weirdly (probably due to inadviseable layout nesting) if I do not use fillviewport=true in my HorizontalScrollView.

Everything works peachy (except for the odd scaling) when fillviewport=false, but when fillviewport=true, the scaling is perfect but no scrolling happens.

This is the layout (Note: I know you're not supposed to put a webview in a scrollview. But webview doesn't have a smoothscrollto nor expose a setscroller method, so ... bleh.)

<?xml version="1.0" encoding="utf-8"?>
<HorizontalScrollView 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/webContainer"
    android:layout_below="@+id/titlebar"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:fillViewport="true">
    <WebView 
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/webZ"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
    />
</HorizontalScrollView>

Setting android:fillViewport="true" doesn't usually disable scrolling in a view, does it?

It's just supposed to be sure the scrollview fills the viewport regardless of the size of its contents, eh? I think the viewport is the visible area of the screen, and there is definitely more content off the edge of the visible area in the webview, I just can't scroll to it anymore.

I can see from logcat that the scrolling methods are being called, they just don't change the screen. (Unless I set fillviewport to false.)

Was it helpful?

Solution

The problem is that you use "fill_parent," which means "be as big as my parent." Use wrap_content for the width instead.

OTHER TIPS

I encounter a similar problem with a standard ScrollView containing a WebView: the scrolling was not working anymore. Changing of fill_parent to wrap_content did not worked for me.

The example of Romain Guy is working fine when the expanded view is a TextView but is not when it's replaced by WebView.

What is not working:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    android:fillViewport="true">
    <LinearLayout
        android:layout_width="fill_parent" android:layout_height="wrap_content"
        android:orientation="vertical">
        <WebView android:id="@+id/webview"
            android:layout_width="fill_parent" android:layout_height="wrap_content"
            android:layout_weight="1.0">
        </WebView>
        <Button 
            android:layout_width="fill_parent" android:layout_height="wrap_content"
            android:text="Click">
        </Button>
    </LinearLayout>     
</ScrollView>

When I add a small amount of data in the webview it seems ok:

small_data_not_ok1

But when I fill the WebView with a lot of data, it does not work as you can see below:

small_data_not_ok2

The button is always displayed and the scroll does not work anymore. In fact, the touch scroll does not work and the DPAD scroll works...

I did not found any reason for that but I found a workaround: it consist in adding a LinearLayout containing the WebView

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    android:fillViewport="true">
    <LinearLayout
        android:layout_width="fill_parent" android:layout_height="wrap_content"
        android:orientation="vertical">
        <LinearLayout android:id="@+id/linearlayout"
            android:layout_width="fill_parent" android:layout_height="wrap_content"
            android:layout_weight="1.0"
            android:orientation="vertical">
            <WebView android:id="@+id/webview"
                android:layout_width="fill_parent" android:layout_height="wrap_content">
            </WebView>
        </LinearLayout>
        <Button 
            android:layout_width="fill_parent" android:layout_height="wrap_content"
            android:text="Click">
        </Button>
    </LinearLayout>     
</ScrollView>

Now it works fine:

ok1 ok2

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top