2012-11-22 162 views
0

我只想知道我是否可以獲取列表是否已經開始滾動,以及何時滾動停止。Android:獲取列表視圖的滾動

我的代碼片段如下:

listView.setOnScrollListener(new OnScrollListener() { 

      public void onScrollStateChanged(AbsListView arg0, int arg1) { 
       // TODO Auto-generated method stub 
       /*View toolbar = arg0.findViewById(R.id.toolbar); 

       // Creating the expand animation for the item 
       ExpandAnimation expandAni = new ExpandAnimation(toolbar, 500);*/ 

       // Start the animation on the toolbar 

      } 

      public void onScroll(AbsListView arg0, int arg1, int arg2, int arg3) { 
       // TODO Auto-generated method stub 
       if(arg1!=0){ 
        toolbar.setVisibility(View.GONE); 
       } 
       else{ 

       } 
      } 
     }); 
+0

閱讀onScrollListener文檔。即使沒有圖像,也沒有那麼長。 – njzk2

回答

0

你只需要看看scrollState參數在onScrollStateChanged回調:

list.setOnScrollListener(new OnScrollListener() { 

     @Override 
     public void onScrollStateChanged(AbsListView view, int scrollState) { 
      switch(scrollState) { 
      case OnScrollListener.SCROLL_STATE_TOUCH_SCROLL: 
       // Scrolling just started 
       break; 
      case OnScrollListener.SCROLL_STATE_FLING: 
       // User just removed his finger (but still scrolling) 
       break; 
      case OnScrollListener.SCROLL_STATE_IDLE: 
       // Scrolling is finished 
       break; 
      } 
     } 

     @Override 
     public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { 
     } 
    }); 
+0

我正在設置動畫,但滾動結束後動畫也停止了。 – Aditya1510

+0

呃......你在說什麼動畫? – fiddler

+0

展開動畫列表.. – Aditya1510