![](/img/trans.png)
[英]When scroll down in GridView and again when scroll up image are again loaded
[英]GridView scroll down and up when click on buttons?
我有一個帶有GridView的視圖和兩個按鈕(向上和向下)。當我們點擊向下按鈕時,gridview將向下滾動並點擊向上按鈕gridview將向上滾動。有任何機會這樣做。請任何一個給予指導(或教程)去做。請幫助我
如果使用api 8或更高的gridview.scrollTo(x, y)
如果使用較低的api gridview.scrollTo(x, y)
則需要使用smoothScrollToPosition()
計算要顯示的第一個圖像的位置並在gridview中設置該位置
Step-1從貪婪視圖中獲取第一個和最后一個圖像位置
步驟2當用戶點擊按鈕時,所選位置為last visible image position +1
當用戶點擊按鈕時,將所選位置存儲為first visible image position -1
步驟-3使用設置圖像選擇並通過傳遞x滾動網格視圖和圖像的坐標使用gridview.scrollTo(x, y)
表示較低的api,並使用smoothScrollToPosition(position)
表示api 8或更高版本
您應該查看smoothScrollToOffset(int offset)
和smoothScrollToPosition(int position)
,它們都是GridView函數。
我建議使用smoothScrollToPosition(int position)
因為它將您想要滾動到的視圖的位置(在您的適配器中)作為參數。 據推測,您可以知道適配器中要滾動到的位置。
在這里查看參考: http : //developer.android.com/reference/android/widget/GridView.html
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.