我想在列表视图上为onFling事件设置动画。
动画效果很好,但行错了。
例如:
CODE:
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
int position = listView.pointToPosition(Math.round(e1.getX()),
Math.round(e1.getY()));
View row = listView.getChildAt(position);
TranslateAnimation anim = null;
if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH || row == null)
return true;
if (e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE
&& Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
anim = new TranslateAnimation(Animation.RELATIVE_TO_SELF,1,Animation.RELATIVE_TO_SELF, 0,
Animation.RELATIVE_TO_SELF,0,Animation.RELATIVE_TO_SELF,0);
this.handleSwipe.onHandleSwipeLeft(position);
} else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE
&& Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
anim = new TranslateAnimation(Animation.RELATIVE_TO_SELF,-1,Animation.RELATIVE_TO_SELF, 0,
Animation.RELATIVE_TO_SELF,0,Animation.RELATIVE_TO_SELF,0);
this.handleSwipe.onHandleSwipeRight(position);
}else{
return true;
}
anim.setDuration(500);
row.startAnimation(anim);
return true;
}
OBS:
已经调试,位置和行总是正确的。
我正在使用api 7级。
该代码在Android 4.2上正常工作
答案 0 :(得分:0)
Guilherme,可能是代码:
int position = listView.pointToPosition(Math.round(e1.getX()),
Math.round(e1.getY()));
未返回行ID 3.您能确认吗?