Android ScrollView取消惯性滚动

释放双眼,带上耳机,听听看~!

【Android ScrollView取消惯性滚动】

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 Studio JNI生成so库

2020-4-15 21:03:03

Android文章

Android获取设备IMEI和Mac地址

2020-4-15 22:18:03

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
有新消息 消息中心
搜索