Android在Gingerbread中引入了新的Overscroll功能,并发现了一些更有趣的东西。
框架中内置了使 View 滚动超出其范围然后反弹的功能(几乎完全类似于iOS),但只是隐藏了。
最佳答案
您可以尝试一下。您的问题的解决方案。
scrollView = (ScrollView) findViewById(R.id.scr);
contentView = (ViewGroup) findViewById(R.id.r2);
scrollView.setOnTouchListener(new ScrollPager(scrollView, contentView));
scrollView.post(new Runnable() {
public void run() {
scrollView.scrollTo(0, contentView.getPaddingTop());
}
});
为此,您需要scroolerPager类。拿到这里
public class ScrollPager implements OnTouchListener
public ScrollPager(ScrollView aScrollView, ViewGroup aContentView)
{
mScrollView = aScrollView;
mContentView = aContentView;
scroller = new Scroller(mScrollView.getContext(), new OvershootInterpolator());
task = new Runnable()
{
public void run()
{
scroller.computeScrollOffset();
mScrollView.scrollTo(0, scroller.getCurrY());
if (!scroller.isFinished())
{
mScrollView.post(this);
}
}
};
}