Android ScrollView doesn't start at top, but at the beginning of the GridView

Solution 1:

Solution:

Ok sorry if it is a late reply but I stumbled upon the same issue (only that I was using ListView instead) and with a bit of trial and error I found the solution to this:

Basically the problem lies in the fact that the GridView/ListView child automatically requests parent focus (ScrollView) when you "hack" and resize its content with ExpandableHeightGridView, which happens after layout is rendered, and hence you see that animation when trying to scroll it up with scrollTo() (happens AFTER layout is created and AFTER gridView is resized so any generic callback is useless to handle this programatically).

So then, the simplest solution I found was to simply disable focusable property on the ListView/GridView with:

listView.setFocusable(false);

That way when you first enter the activity, focus will default and not rely on Listview/GridView.

And all working fine =)

Solution 2:

The easiest way is to add on the parent ScrollView the following xml attributes:

android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true"

That means that the ScrollView as a whole will be the one getting focus instead of any inner container when you launch the activity. This is also useful, for example, when you have an edit text inside your layout and you don't want it to get focus immediately and popup the keyboard when entering a screen (It's the same principle).

So, your ScrollView on top of your layout would look like this:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/scrollViewLuogo"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:descendantFocusability="beforeDescendants"
    android:focusableInTouchMode="true"
    android:background="#fff" >

Solution 3:

Simply add this line of code in the Child of ScrollView

android:focusableInTouchMode="true"