Android ScrollView取消惯性滚动的方法
时间:2021-02-26 10:51:16|栏目:Android代码|点击: 次
ScrollView中惯性滚动的效果,想让这个ScrollView慢一点滑动或者接近drag(拖拽)操作,就提出了添加阻尼的说法。只要重新fling方法即可,将velocity值极至缩小。
实例如下:
public class CustomHorizontalScrollView extends HorizontalScrollView { private Context context; private ScrollViewListenner listenner; private CustomHorizontalScrollView currentView; public CustomHorizontalScrollView(Context context) { super(context); // TODO Auto-generated constructor stub this.context = context; } public CustomHorizontalScrollView(Context context, AttributeSet attrs) { super(context, attrs); // TODO Auto-generated constructor stub this.context = context; } public CustomHorizontalScrollView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); // TODO Auto-generated constructor stub this.context = context; } @Override public boolean onTouchEvent(MotionEvent ev) { // TODO Auto-generated method stub currentView = this; return super.onTouchEvent(ev); } @Override protected void onScrollChanged(int l, int t, int oldl, int oldt) { // TODO Auto-generated method stub if (null != listenner) { this.listenner.onScrollChanged(currentView, l, t, oldl, oldt); } super.onScrollChanged(l, t, oldl, oldt); } public interface ScrollViewListenner { public void onScrollChanged(CustomHorizontalScrollView view, int l, int t, int oldl, int oldt); } public void setScrollViewListenner(ScrollViewListenner listenner) { this.listenner = listenner; } /** * *阻尼:1000为将惯性滚动速度缩小1000倍,近似drag操作。 @Override public void fling(int velocity) { super.fling(velocity / 1000); } */ }
栏 目:Android代码
下一篇:Android动态布局使用详解
本文标题:Android ScrollView取消惯性滚动的方法
本文地址:http://www.codeinn.net/misctech/70146.html