Pat*_*oos 15
Android中的新兼容包(第3版)添加了一个ViewPager,可以实现这一点.
http://developer.android.com/sdk/compatibility-library.html
Dav*_*sti 13
所以,我的解决方案是:
方法computeScroll被调用以移动列表.默认情况下,我认为它的实现是以一定的比例减速...因为我不想要这个动作,所以我只是覆盖它而不指定一个体.
事件处理程序的代码是:
_scrollView.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if(event.getAction() == MotionEvent.ACTION_UP)
{
float currentPosition = _scrollView.getScrollX();
float pagesCount = _horizontalBar.getChildCount();
float pageLengthInPx = _horizontalBar.getMeasuredWidth()/pagesCount;
float currentPage = currentPosition/pageLengthInPx;
Boolean isBehindHalfScreen = currentPage-(int)currentPage > 0.5;
float edgePosition = 0;
if(isBehindHalfScreen)
{
edgePosition = (int)(currentPage+1)*pageLengthInPx;
}
else
{
edgePosition = (int)currentPage*pageLengthInPx;
}
_scrollView.scrollTo((int)edgePosition, 0);
}
return false;
}
});
Run Code Online (Sandbox Code Playgroud)
在我继承的HorizontalScrollView中
@Override
public void computeScroll (){
return;
}
Run Code Online (Sandbox Code Playgroud)