views:

49

answers:

1

I am trying to port an existing iPhone application to android. I wish to have a button scroll into view at the bottom of a GridView to enable the user to load more data from the server. Presently, my solution simply fixes a button at the bottom of the screen instead of having it scroll into view.

Here is my layout code:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical"    
        >   
        <GridView xmlns:android="http://schemas.android.com/apk/res/android" 
            android:id="@+id/grid"
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content"
            android:columnWidth="70dp"
            android:numColumns="auto_fit"
            android:verticalSpacing="0dp"
            android:horizontalSpacing="0dp"
            android:stretchMode="columnWidth"
            android:gravity="center"
            android:background="#000000"
        />
        <Button
        android:id="@+id/load_more"
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"
        android:text="Load More" 
        />
    </LinearLayout>

Fixing the button at the bottom of the screen won't work because I plan on placing an ad at the bottom.

Can anyone either explain conceptually how to get a load more button to scroll into view, or point me to some sample code, OR tell me why this is not idiomatic to Android and what other UI convention it uses to load more data in a GridView?

Thanks!

A: 

You can place a ScrollView inside your main LinearLayout. A ScrollView can only have one direct child, though, so you'll need to put another LinearLayout inside of it which would then contain your GridView and Button.

Blumer
That almost worked....unfortunately the GridView is not sizing itself properly within the ScrollView/LinearLayout. It appears that the GridView only knows how to size itself to the screen, thereby cropping additional rows that don't fit. A layout_height of wrap_content doesn't force the GridView to size itself based on the actual amount of vertical space it needs. Any ideas on this? Can I tell a GridView to size itself to the height it needs programmatically?
esilver