ListView: limit scrolling speed [duplicate]

2019-05-28 11:38发布

问题:

Possible Duplicate:
Android Listview slow down scroll speed

When a user swipes on a ListView its' scrolling speed can get pretty high. I'd like to limit the speed - is it possible ?

回答1:

Check this out -:

private class SpeedMeterOnScrollListener implements OnScrollListener {

        private long timeStamp;
        private int lastFirstVisibleItem;

        public SpeedMeterOnScrollListener() {
            timeStamp = System.currentTimeMillis();
            lastFirstVisibleItem = 0;
        }

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            long lastTime = System.currentTimeMillis();
            //calculate speed by firstVisibleItem, lastFirstVisibleItem, timeStamp and lastTime
            timeStamp = lastTime;
            lastFirstVisibleItem = firstVisibleItem;
        }

        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {
        }
    }