3

我正在自动滚动列表视图,其中包含 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;
               }
    }
4

2 回答 2

1

如下设置平滑 Scollbars listview

listView.setSmoothScrollbarEnabled(true);
于 2013-06-25T12:07:12.607 回答
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);
}
于 2014-03-07T16:15:44.203 回答