This is how I realize this effect. We have a ListView lvSimple
and we add onTouchListener to our lvSimple
. This is my working code.
float historicX = Float.NaN, historicY = Float.NaN;
static final int DELTA = 50;
enum Direction {LEFT, RIGHT;}
...
ListView lvSimple = (ListView) findViewById(R.id.linLayout);
...
lvSimple.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
historicX = event.getX();
historicY = event.getY();
break;
case MotionEvent.ACTION_UP:
if (event.getX() - historicX < -DELTA) {
FunctionDeleteRowWhenSlidingLeft();
return true;
}
else if (event.getX() - historicX > DELTA) {
FunctionDeleteRowWhenSlidingRight();
return true;
}
break;
default:
return false;
}
return false;
}
});
where function FunctionDeleteRowWhenSlidingLeft()
is calling when when we sliding to the left, FunctionDeleteRowWhenSlidingRight()
- to the right respectively. In this function you need paste code for animation.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…