new*_*bie 8 android android-animation android-listview android-gesture
我正在尝试在Android ICS及更高版本中实现"从左向右滑动以删除"手势.我的应用程序中有listview.我有手势探测器工作.但是当我在特定列表项目上从左向右滑动时,我希望项目随着我的手指移动.当我移动手指时,超过某一点,只有这样项目才会自行删除.OnFling()方法I目前还没有实现这一目标.
如何修改OnFling()方法以使项目随我的手指移动?
我的手势听众课是
class GestureListener extends SimpleOnGestureListener {
private static final int SWIPE_MIN_DISTANCE = 50;
private static final int SWIPE_MAX_OFF_PATH = 100;
private static final int SWIPE_THRESHOLD_VELOCITY = 25;
private MotionEvent mLastOnDownEvent = null;
@Override
public boolean onDown(MotionEvent e) {
mLastOnDownEvent = e;
return super.onDown(e);
}
@Override
public boolean onSingleTapUp(MotionEvent e) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "On Single TAP up ", Toast.LENGTH_SHORT).show();
return super.onSingleTapUp(e);
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
if (e1 == null) {
e1 = mLastOnDownEvent;
}
if (e1 == null || e2 == null) {
return false;
}
float dX = e2.getX() - e1.getX();
float dY = e1.getY() - e2.getY();
if (Math.abs(dY) < SWIPE_MAX_OFF_PATH
&& Math.abs(velocityX) >= SWIPE_THRESHOLD_VELOCITY
&& Math.abs(dX) >= SWIPE_MIN_DISTANCE) {
if (dX > 0) {
int position = tasks.pointToPosition((int) e1.getX(),
(int) e1.getY());
int _id = (int) tasks.getItemIdAtPosition(position);
databaseConnector.deleteContact(_id);
new DeleteRow(_id, contactAdapter, getApplicationContext());
contactAdapter.notifyDataSetChanged();
Toast.makeText(getApplicationContext(),
"Right Swipe" + _id, Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getApplicationContext(), "Left Swipe",
Toast.LENGTH_SHORT).show();
}
return true;
}
return false;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
20862 次 |
| 最近记录: |