如何在listview中获得平滑滚动

时间:2013-06-25 12:03:56

标签: android listview

我是自动滚动列表视图,里面有1000个项目。通过运行一个运行smoothscroll的线程,我让用户通过停止线程直到列表视图滚动并再次启动线程来刷列表视图。事情很好,但问题是刷卡后自动滚动之间有延迟。如何从滑动滚动平滑过渡到自动滚动。

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;
               }
    }

2 个答案:

答案 0 :(得分:1)

listview设置平滑Scollbars,如下所示:

listView.setSmoothScrollbarEnabled(true);

答案 1 :(得分: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);
}