滑动动画
参考
float posX = 0, posY = 0, curPosX = 0, curPosY = 0;
imageView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()){
case MotionEvent.ACTION_DOWN:
posX = event.getX();
posY = event.getY();
break;
case MotionEvent.ACTION_MOVE:
curPosX = event.getX();
curPosY = event.getY();
break;
case MotionEvent.ACTION_UP:
if ((curPosX - posX > 0) && (Math.abs(curPosX - posX) > 100)) {
if (index > 0) {
moveImage(--index);
TranslateAnimation animation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, -1.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f);
animation.setRepeatMode(Animation.REVERSE);
animation.setDuration(500);
imageView.startAnimation(animation);
}
} else if ((curPosX - posX < 0) && (Math.abs(curPosX-posX) > 100)) {
if (index < list_image.size() - 1) {
moveImage(++index);
TranslateAnimation animation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 1.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f);
animation.setRepeatMode(Animation.REVERSE);
animation.setDuration(500);
imageView.startAnimation(animation);
}
}
break;
}
return true;
}
});
虽然动画很酷,但也只是动画,和图库的拖动切换照片体验差很多。