换个思路,不用button而是重绘上层组件的背景呢?
现在滑动解锁应该就是这个思路实现的。
附一段我写的解锁的代码吧
@SuppressWarnings("deprecation")
@Override
public boolean onTouchEvent(MotionEvent event) { int x = (int) event.getX() ;
if(isSelect){
if (x >= dragPartRight) {
rightimg.setBackgroundDrawable(rightdown);
} else if (x <= dragPartLeft) {
leftimg.setBackgroundDrawable(leftdown);
} else {
rightimg.setBackgroundDrawable(rightup);
leftimg.setBackgroundDrawable(leftup);
}
}
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
downflag=true;
mLastMoveX = x;
// 处理Action_Down事件: 判断是否点击了滑动区域
return handleActionDownEvenet(event);
case MotionEvent.ACTION_MOVE:
mLastMoveX = x; // 保存了X轴方向
invalidate(); // 重新绘制
return true;
case MotionEvent.ACTION_UP:
// 处理Action_Up事件: 判断是否解锁成功,成功则结束我们的Activity ;否则 ,缓慢回退该图片。
isSelect=false;
handleActionUpEvent(event);
}
return super.onTouchEvent(event);
}
现在滑动解锁应该就是这个思路实现的。
附一段我写的解锁的代码吧
@SuppressWarnings("deprecation")
@Override
public boolean onTouchEvent(MotionEvent event) { int x = (int) event.getX() ;
if(isSelect){
if (x >= dragPartRight) {
rightimg.setBackgroundDrawable(rightdown);
} else if (x <= dragPartLeft) {
leftimg.setBackgroundDrawable(leftdown);
} else {
rightimg.setBackgroundDrawable(rightup);
leftimg.setBackgroundDrawable(leftup);
}
}
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
downflag=true;
mLastMoveX = x;
// 处理Action_Down事件: 判断是否点击了滑动区域
return handleActionDownEvenet(event);
case MotionEvent.ACTION_MOVE:
mLastMoveX = x; // 保存了X轴方向
invalidate(); // 重新绘制
return true;
case MotionEvent.ACTION_UP:
// 处理Action_Up事件: 判断是否解锁成功,成功则结束我们的Activity ;否则 ,缓慢回退该图片。
isSelect=false;
handleActionUpEvent(event);
}
return super.onTouchEvent(event);
}
现在滑动解锁应该就是这个思路实现的。
附一段我写的解锁的代码吧
@SuppressWarnings("deprecation")
@Override
public boolean onTouchEvent(MotionEvent event) { int x = (int) event.getX() ;
if(isSelect){
if (x >= dragPartRight) {
rightimg.setBackgroundDrawable(rightdown);
} else if (x <= dragPartLeft) {
leftimg.setBackgroundDrawable(leftdown);
} else {
rightimg.setBackgroundDrawable(rightup);
leftimg.setBackgroundDrawable(leftup);
}
}
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
downflag=true;
mLastMoveX = x;
// 处理Action_Down事件: 判断是否点击了滑动区域
return handleActionDownEvenet(event);
case MotionEvent.ACTION_MOVE:
mLastMoveX = x; // 保存了X轴方向
invalidate(); // 重新绘制
return true;
case MotionEvent.ACTION_UP:
// 处理Action_Up事件: 判断是否解锁成功,成功则结束我们的Activity ;否则 ,缓慢回退该图片。
isSelect=false;
handleActionUpEvent(event);
}
return super.onTouchEvent(event);
}