Why is onScrollChanged never called?
<p>I have a relative layout that is embedded into two nested scrollviews: a vertical scroll view goes first, it contains a horizontal scroll view, which in turn contains the "payload" (hereinafter content).</p>

<p>I want to handle scrolling of the content. After some searching, I've found the ViewTreeObserver.OnScrollChangedListener, and it looks like what I want.</p>

<p>I've created the listener and attached it to every view in my hierarchy; however the onScrollChanged() is never called, although the content is scrolling in both directions.</p>

<p>My target API level is 7, if that makes sense.</p>

<p>Here is my XML (I've put the long text there intentionally to make the view both high and wide enough):</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/main"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" &gt;

    &lt;ScrollView
        android:id="@+id/verticalScroll"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        tools:ignore="HardcodedText,UselessParent" &gt;

        &lt;HorizontalScrollView
            android:id="@+id/horizontalScroll"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" &gt;

            &lt;RelativeLayout
                android:id="@+id/content"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent" &gt;

                &lt;TextView
                    android:id="@+id/textView1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:maxWidth="240dp"
                    android:minLines="5"
                    android:text="Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text "
                    android:textAppearance="?android:attr/textAppearanceLarge" /&gt;

                &lt;Button
                    android:id="@+id/button1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/textView1"
                    android:text="Button" /&gt;

                &lt;TextView
                    android:id="@+id/textView2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentLeft="true"
                    android:layout_below="@+id/button1"
                    android:text="Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text "
                    android:textAppearance="?android:attr/textAppearanceLarge" /&gt;

                &lt;TextView
                    android:id="@+id/textView3"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/textView2"
                    android:maxWidth="240dp"
                    android:minLines="5"
                    android:text="Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text Large Text "
                    android:textAppearance="?android:attr/textAppearanceLarge" /&gt;

                &lt;Button
                    android:id="@+id/button2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/textView1"
                    android:layout_toRightOf="@+id/button1"
                    android:text="Button" /&gt;

                &lt;Button
                    android:id="@+id/button3"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/textView1"
                    android:layout_toRightOf="@+id/button2"
                    android:text="Button" /&gt;
            &lt;/RelativeLayout&gt;
        &lt;/HorizontalScrollView&gt;
    &lt;/ScrollView&gt;

&lt;/RelativeLayout&gt;
</code></pre>

<p>And here is the Java code:</p>

<pre><code>public class ScrollActivity extends Activity {

    private OnScrollChangedListener _onScroll;
    private RelativeLayout _main;
    private ScrollView _verticalScroll;
    private HorizontalScrollView _horizontalScroll;
    private RelativeLayout _content;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.scroll);

        _main = (RelativeLayout)findViewById(R.id.main);
        _verticalScroll = (ScrollView)findViewById(R.id.verticalScroll);
        _horizontalScroll = (HorizontalScrollView)findViewById(R.id.horizontalScroll);
        _content = (RelativeLayout)findViewById(R.id.content);

        _onScroll = new OnScrollChangedListener() {
            @Override
            public void onScrollChanged() {
                // The line below is never reached,
                // checked that with the debugger.
                Toast.makeText(getApplicationContext(), "Scroll", Toast.LENGTH_SHORT).show();
            }
        };
        _main.getViewTreeObserver().addOnScrollChangedListener(_onScroll);
        _verticalScroll.getViewTreeObserver().addOnScrollChangedListener(_onScroll);
        _horizontalScroll.getViewTreeObserver().addOnScrollChangedListener(_onScroll);
        _content.getViewTreeObserver().addOnScrollChangedListener(_onScroll);
    }
}
</code></pre>
