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

Deadly 提交于 2020-01-15 03:42:08

问题


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!


回答1:


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.




回答2:


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


来源:https://stackoverflow.com/questions/3670176/getting-a-button-to-scroll-into-view-at-the-bottom-of-a-gridview-on-android

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!