2013-06-25 48 views
3

我是自動滾動的listview,其中有1000個項目...通過運行一個運行smoothscroll的線程,我讓用戶通過停止線程來刷新listview,直到列表視圖滾動並再次啓動線程..每一件事情都很好,但問題是在滑動後自動滾動到啓動之間存在延遲。如何從滑動滾動平滑過渡到自動滾動。如何在列表視圖中獲得平滑滾動

protected void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState); 
       -------- 
       -------- 
       ThreadAutoScroll(); 
} 

private void autoScroll() { 


      if(!touched) 
      { 
       listView.smoothScrollBy(1,30); 
      } 

    } 

public onTouch(Moition event) 
{ 
switch(event.getAction()) 
     { 
     case MotionEvent.ACTION_DOWN: 
      touched = true ; 
      break; 
      } 
} 

public void onScrollStateChanged(AbsListView view, int scrollState) { 
     // TODO Auto-generated method stub 

     if(touched && scrollState =0) 
       { 
       touched = true; 
       } 
    } 

回答

1

設置平滑Scollbars爲listview如下:

listView.setSmoothScrollbarEnabled(true); 
+1

我問了什麼..你回答..? – Naruto

0

在你的代碼只是試試這個代碼。我希望這會有所幫助。

GestureDetector mGD = new GestureDetector(getBaseContext(), 
     new SimpleOnGestureListener() { 

@Override 
public boolean onScroll(MotionEvent e1, MotionEvent e2, 
float distanceX, float distanceY) { 
// beware, it can scroll to infinity 
scrollBy((int)distanceX, (int)distanceY); 
return true; 
} 

private void scrollBy(int distanceX, int distanceY) { 
distanceX =10; 
distanceY =10; 
} 

@Override 
public boolean onDown(MotionEvent e) { 
if(!mScroller.isFinished()) { // is flinging 
mScroller.forceFinished(true); // to stop flinging on touch 
} 
return true; // else won't work 
} 
}); 

@Override 
public boolean onTouchEvent(MotionEvent event) { 
return mGD.onTouchEvent(event); 
}