当我们处理TouchEvent事件使用回调函数更方便

1,新创建一个ViewDragHelper
ViewDragHelper mDragHelper = ViewDragHelper.create(this,//
new DragCallBack());
2.在touch时间中捕获Event事件
@Override
public boolean onTouchEvent(MotionEvent event) {
mDragHelper.processTouchEvent(event);
return true;
}

3.
作为事件回调函数
class myCallBack extends ViewDragHelper.Callback{

@Override
public boolean tryCaptureView(View child, int pointerId) {
return false;
}

public myCallBack() {
super();
}

@Override
public int clampViewPositionHorizontal(View child, int left, int dx) {
return super.clampViewPositionHorizontal(child, left, dx);
}

@Override
public int clampViewPositionVertical(View child, int top, int dy) {
return super.clampViewPositionVertical(child, top, dy);
}

@Override
public int getOrderedChildIndex(int index) {
return super.getOrderedChildIndex(index);
}

@Override
public int getViewHorizontalDragRange(View child) {
return super.getViewHorizontalDragRange(child);
}

@Override
public int getViewVerticalDragRange(View child) {
return super.getViewVerticalDragRange(child);
}

@Override
public void onEdgeDragStarted(int edgeFlags, int pointerId) {
super.onEdgeDragStarted(edgeFlags, pointerId);
}

@Override
public boolean onEdgeLock(int edgeFlags) {
return super.onEdgeLock(edgeFlags);
}

@Override
public void onEdgeTouched(int edgeFlags, int pointerId) {
super.onEdgeTouched(edgeFlags, pointerId);
}

@Override
public void onViewCaptured(View capturedChild, int activePointerId) {
super.onViewCaptured(capturedChild, activePointerId);
}

@Override
public void onViewDragStateChanged(int state) {
super.onViewDragStateChanged(state);
}

@Override
public void onViewPositionChanged(View changedView, int left, int top, int dx, int dy) {
super.onViewPositionChanged(changedView, left, top, dx, dy);
}

@Override
public void onViewReleased(View releasedChild, float xvel, float yvel) {
super.onViewReleased(releasedChild, xvel, yvel);
}
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值