horizontalscrollview's fillviewport disables scrolling?
Asked Answered
S

2

6

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

Smaragdine answered 15/3, 2011 at 3:55 Comment(2)
Even if you were to use the scrollTo methods on the HorizontalScrollView, you wouldn't be scrolling the WebView content but the WebView itself. I think you were right to be wary of wrapping one in the other.Corrida
I'd like to find another method for this, but for the life of me can't achieve a smooth horizontal scroll using the methods built in to WebView. :( As the point of my project is to display html, there really isn't any other View that makes sense either.Smaragdine
W
5

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

Woodard answered 15/3, 2011 at 5:32 Comment(0)
A
2

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

Andesine answered 28/6, 2011 at 14:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.