您的位置:首页 > 移动开发 > Android开发

Android ScrollView取消惯性滚动的方法

2017-04-13 10:12 489 查看

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 ScrollView取消惯性滚动的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。

您可能感兴趣的文章:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息