我根據這個主題來實現我的手勢聽衆: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就會導致列表視圖
發佈您的一些代碼,或許在滾動時您的列表項目回收方式效率低下。 – HotN
沒有人,我更新了主題和問題是在手勢檢測器中定義好像我刪除它一切順利 – Phate