[英]Getting a button to scroll into view at the bottom of a GridView on Android
我正在嘗試將現有的iPhone應用程序移植到android。 我希望有一個按鈕滾動到GridView底部的視圖中,以使用戶能夠從服務器加載更多數據。 目前,我的解決方案只是將按鈕固定在屏幕底部,而不是滾動到視圖中。
這是我的布局代碼:
<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>
由於我計划將廣告放在屏幕底部,因此無法將其固定在屏幕底部。
誰能在概念上解釋如何獲取更多加載按鈕以滾動到視圖中,或為我提供一些示例代碼,或者告訴我為什么這不是Android慣用的,以及它用於在GridView中加載更多數據的其他UI約定?
謝謝!
您可以在主LinearLayout中放置一個ScrollView。 但是,一個ScrollView只能有一個直接子級,因此您需要在其中放入另一個LinearLayout,然后再包含GridView和Button。
滾動GridView並刷新基礎數據后,我遇到了類似的問題,注意到scoll並未重置為開始。 我用以下代碼片段解決了它
gvKeys.setSelection(0);
我猜想,如果您知道網格中的項目數N ,那么以下方法將起作用:
gvKeys.setSelection(N);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.