horizontalscrollview's fillviewport disables scrolling?

Turnsole picture Turnsole · Mar 15, 2011 · Viewed 10k times · Source

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

Answer

Romain Guy picture Romain Guy · Mar 15, 2011

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