터치 이벤트를 써서 원하는 방향으로 슬라이드 되게 하였습니다...
왼쪽은 잘되는데 오른쪽으로 갈때 문제가 생기네요;;;
왼쪽으로 갈때는
flipper.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.left_in));
flipper.setOutAnimation(AnimationUtils.loadAnimation(this, R.anim.left_out));
flipper.showNext();
을 실행하고 오른쪽으로 갈때는
flipper.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.right_in));
flipper.setOutAnimation(AnimationUtils.loadAnimation(this, R.anim.right_out));
flipper.showPrevious();
을 실행합니다.
왼쪽으로 갈때는 잘 되는데
오른쪽으로 갈때 (1,2번 사진이 있을때 2번에서 1번으로 옮기면)
2번과 1번이 사진이 바뀌면서 오른쪽 슬라이딩이 되고 다시 2번과 1번 사진이 바뀝니다 --;
결과 적으로는 맞게 나오는데 슬라이딩 될때 이미지가 두번 뒤바뀌는..
flipper.addView(imgView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.FILL_PARENT));
imgView.setOnTouchListener(new OnTouchListener(){
float startX=0, startY=0;
public boolean onTouch(View v, MotionEvent event){
...
...
if(왼쪽으로 터치){
if(gapX > 0){
anim(0);
flipper.showNext();
}
else{
anim(1);
flipper.showPrevious();
}
}
}
return true;
}
});
위에서 anim() 은
public void anim(Integer type){
if(type == 0){
flipper.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.left_in));
flipper.setOutAnimation(AnimationUtils.loadAnimation(this, R.anim.left_out));
} else{
flipper.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.right_in));
flipper.setOutAnimation(AnimationUtils.loadAnimation(this, R.anim.right_out));
}
}
입니다.
next를 두개 쓰면 이전 그림이 나와야 되는데 다음 그림이 나오더라구요.. 구글링으로 해결 했습니다 ^^;
anim(1);
flipper.setInAnimation(animateInFrom(LEFT));
flipper.setOutAnimation(animateOutTo(RIGHT));
flipper.showPrevious();
private static final int LEFT = 0;
private static final int RIGHT = 1;
private Animation animateInFrom(int fromDirection) {
Animation inFrom = null;
switch (fromDirection) {
case LEFT:
inFrom = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, -1.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f);
break;
case RIGHT:
inFrom = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, +1.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f);
break;
}
inFrom.setDuration(250);
inFrom.setInterpolator(new AccelerateInterpolator());
return inFrom;
}
private Animation animateOutTo(int toDirection) {
Animation outTo = null;
switch (toDirection) {
case LEFT:
outTo = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, -1.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f);
break;
case RIGHT:
outTo = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, +1.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f);
break;
}
outTo.setDuration(250);
outTo.setInterpolator(new AccelerateInterpolator());
return outTo;
}