作者热门文章
- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
在Android中,我们如何检测用户是否触摸按钮并拖出该按钮的区域?
最佳答案
检查 MotionEvent.MOVE_OUTSIDE:
检查 MotionEvent.MOVE:
private Rect rect; // Variable rect to hold the bounds of the view
public boolean onTouch(View v, MotionEvent event) {
if(event.getAction() == MotionEvent.ACTION_DOWN){
// Construct a rect of the view's bounds
rect = new Rect(v.getLeft(), v.getTop(), v.getRight(), v.getBottom());
}
if(event.getAction() == MotionEvent.ACTION_MOVE){
if(!rect.contains(v.getLeft() + (int) event.getX(), v.getTop() + (int) event.getY())){
// User moved outside bounds
}
}
return false;
}
注意:如果您想以 Android 4.0 为目标,则会打开一个充满新可能性的世界: http://developer.android.com/reference/android/view/MotionEvent.html#ACTION_HOVER_ENTER
关于Android:检测用户是否触摸并拖出按钮区域?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6410200/
我有一个包含许多项目的 NSTableView。我想实现从 NSTableView 的内部 拖动到 外部 以删除拖动的项目。 (有点像 Safari 如何“噗”掉书签。) NSTableView 已经
我有一个列表,我正在尝试创建一个系统,在该系统中,人们可以将元素从该列表拖动到 div(而不是其他列表),反之亦然。下面是我的代码: $(function() { $( "ul, li" ).disa
我是一名优秀的程序员,十分优秀!