Component类中:
        //设置滚动条灵敏度
        public void pointerReleased(int x, int y) {
        
if (dragActivated) {
            
long currentTime = System.currentTimeMillis();

            
// replace x and y if this is an x scrolling container
            if (!isScrollableY()) {
                y 
= x;
            }

            
if (currentTime != lastTime[(pLastDragged + lastTime.length + 1% lastTime.length]) {
                lastTime[pLastDragged] 
= System.currentTimeMillis();
                lastDragged[pLastDragged] 
= y;
                pLastDragged 
= (++pLastDragged) % lastTime.length;
            }
            
float velocity = (float) (lastDragged[pLastDragged] - lastDragged[(pLastDragged + lastDragged.length + 1% lastDragged.length]) / (lastTime[pLastDragged] - lastTime[(pLastDragged + lastTime.length + 1% lastTime.length]);
            velocity 
= velocity * -1;

       
//默认为0.0004f ,越小灵敏度越高
            if (isScrollableY()) {
                draggedMotion 
= Motion.createFrictionMotion(scrollY, velocity, 0.0008f);
            } 
else {
                draggedMotion 
= Motion.createFrictionMotion(scrollX, velocity, 0.0008f);
            }


            draggedMotion.start();
            dragActivated 
= false;
        }
    }
posted on 2009-08-10 08:59  tatung zhang  阅读(1037)  评论(4编辑  收藏  举报