开发者

Getting a button to scroll into view at the bottom of a GridView on Android

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:columnWidt开发者_运维技巧h="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!


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.


I had a similar problem with scrolling a GridView and after refreshing the underlying data, noticing that the scoll was not reset to the beginning. I solved it with the following code fragment

gvKeys.setSelection(0);

I'm guessing that if you know the number of items in your grid, N, that the following will work:

gvKeys.setSelection(N);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜