2010-11-04 36 views
0

如果在列表底部有一個按鈕,所以當你向下滾動並且列表已經結束時,會出現一個按鈕「Get more」,它將填充與更多項目的列表。Android:當列表已經結束比它應該顯示按鈕

但該按鈕不可見。這是我的xml文件的樣子。 也許這是因爲卷軸發生,也許卷軸只適用於列表。

<ListView 
     android:id="@+id/android:list" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" /> 

    <Button android:id="@+id/search_browser" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="Get more ads" /> 
</LinearLayout> 

回答

2

這並不是真正做到這一點的正確方法。 在你的情況下,該按鈕總是在列表的底部可見。 如果你希望它是可見的,只有當用戶滾動底部,使用方法:

yourListView.addFooterView(someFooterView) 

這頁腳視圖可以(邏輯)是任何視圖(按鈕佈局),充氣,或在運行時創建。

P.S. http://developer.android.com/reference/android/widget/ListView.html#addFooterView(android.view.View

P.S.S.在你的情況下,你需要刪除XML中的按鈕聲明,只留下ListView。 並在代碼中做

Button button = new Button(this); button.setText("Get more ads"); ((ListView) findViewById(R.id.list).addFooterView(button);

0

嘗試以下方法:的

android:layout_height="fill_parent" 

android:layout_height="0dip" 
android:layout_weight="1" 

,而不是你的ListView。

但我認爲,更合適的是有一個auto-growing list

相關問題