2013-08-21 48 views
0

我試圖知道用戶何時滾動屏幕末端。如何知道用戶是否滾動屏幕末端

我的佈局是ScrollView。

我創造新的服裝滾動型對象覆蓋onScrollChanged使用這裏的代碼:

Detect end of ScrollView

我對用戶滾動時知道該屏幕的結束碼是:

創建視圖在我的佈局下我的scrollview調用checkEndOfList

在我的代碼中,我嘗試檢查列表的結尾,如果顯示。

我的XML:

<com.example.workoutlog.WallScrollView 
     android:id="@+id/wallList" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:stackFromBottom="true" 
     android:transcriptMode="alwaysScroll" > 

     <LinearLayout 
      android:id="@+id/workoutsWall" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" > 
     </LinearLayout> 
    </com.example.workoutlog.WallScrollView> 

    <LinearLayout 
     android:id="@+id/checkEndOfList" 
     android:layout_width="fill_parent" 
     android:layout_height="0.1sp" 
     android:layout_below="@+id/wallList" 
     android:orientation="horizontal" 
     android:background="@color/transparent" > 
    </LinearLayout> 

這是我檢查java代碼是在頁面的末端用戶滾動:

@Override 
     public void onScrollChanged(WallScrollView scrollView, int x, 
       int y, int oldx, int oldy) { 
      // TODO Auto-generated method stub   
      if(y - oldy == 0 && checkEndOfList.isShown() && y != 0 && oldy != 0) 
      { 
//MY CODE 
} 

我想行得爲我工作的代碼。即使當我沒有滾動屏幕時,我也會接到屏幕結束的呼叫。

感謝您的幫助。

回答

0

,你可以用這樣的方式:

private int visibleThreshold = 5; 
    private int currentPage = 0; 
    private int previousTotal = 0; 
    private boolean loading = true; 

    @Override 
    public void onScroll(AbsListView view, int firstVisibleItem, 
      int visibleItemCount, int totalItemCount) { 
     if (loading) { 
      if (totalItemCount > previousTotal) { 
       loading = false; 
       previousTotal = totalItemCount; 
       currentPage++; 
      } 
     } 
     if (!loading && (totalItemCount - visibleItemCount) <= (firstVisibleItem + visibleThreshold)) { 
      // I load the next page of gigs using a background task, 
      // but you can call any function here. 
      new LoadGigsTask().execute(currentPage + 1); 
      loading = true; 
     } 
    } 
相關問題