2012-09-28 66 views
1

我根據這個主題來實現我的手勢聽衆:ListView Horizontal Fling Gesture與列表視圖水平掃視:滯後的問題

不過,我可以看到滾動列表速度慢,有時(當您滾動很慢),它阻止了。 我認爲問題出在監聽器中:計算值需要時間,因此我正在尋找實際的「從左到右」的投射......沒有更有效的方法嗎?

編輯

問題是在這裏:

@Override 
    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { 
     if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH) { 
      return false; 
     } 

     // right to left swipe 
     if(e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) { 
      System.out.println("right to left"); 
      animatedStartActivity(0); 

      // right to left swipe 
     } else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) { 
      System.out.println("left to right"); 
      animatedStartActivity(1); 
     } 

     return false; 
    } 

這種方法的評價需要時間

EDIT2: 我猜問題是因爲列表視圖已經擁有了自己的姿態偵聽器和附上我的覆蓋它。這是一個問題,因爲listview手勢監聽器也考慮到速度和加速度,以提供一個不錯的移動效果。我的聽衆是相當原始,所以滾動列表不順暢了.. 即使我onFLing方法始終返回false(所以它不會消​​耗事件)列表滾動受到影響......

EDIT3: 好吧,也許我找到了解決方案,但我需要你的幫助! 我可以在容器佈局上設置onTouchListener,問題在於listview實際上覆蓋了父級的onTouch,所以我需要顛倒這種情況:listview上的onTouchEvent必須被父級攔截,這樣返回false就會導致列表視圖

+1

發佈您的一些代碼,或許在滾動時您的列表項目回收方式效率低下。 – HotN

+0

沒有人,我更新了主題和問題是在手勢檢測器中定義好像我刪除它一切順利 – Phate

回答

0

已解決!!! 問題是ListView的onTouchEvent執行了一些其他操作!所以,我的ListView擴展:

public class FlingListView extends ListView{ 

private GestureDetector detector; //this is my detector 

public void setDetector(GestureDetector detector){ 
    this.detector = detector; 
} 

public FlingListView(Context context) { 
    super(context); 
    // TODO Auto-generated constructor stub 
} 

public FlingListView(Context context,AttributeSet set) { 
    super(context,set); 
    // TODO Auto-generated constructor stub 
} 

public FlingListView(Context context,AttributeSet set, int a) { 
    super(context,set,a); 
    // TODO Auto-generated constructor stub 
} 

    //here I do the magic 
@Override 
public boolean onTouchEvent(MotionEvent ev) { 
    // TODO Auto-generated method stub 
    super.onTouchEvent(ev); //I always do the list on touch event 
    return(detector.onTouchEvent(ev)); //..but I return the detector! 

} 
} 

我不知道這是不是最好的解決辦法,但仍...它的作品!