안드로이드 개발 질문/답변
(글 수 45,052)
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
// Touch Event in ViewFlipper case
if(v != mflipper) return false;
if(event.getAction() == MotionEvent.ACTION_DOWN) {
xAtDown = event.getX(); // Touch Start Position save X
}
else if(event.getAction() == MotionEvent.ACTION_UP) {
xAtUp = event.getX(); // Touch End Position save X
if(xAtUp < xAtDown) {
// Left Animation
mflipper.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.push_left_in));
mflipper.setOutAnimation(AnimationUtils.loadAnimation(this, R.anim.push_left_out));
count--;
if(count < 0) {
count = imageList.length - 1;
}
Bitmap bmp = BitmapFactory.decodeFile(imgpath + imageList[count]);
mImageView.setImageBitmap(bmp);
// Next View
mflipper.showNext();
showToast(imageList[count]);
}
else if(xAtUp > xAtDown) {
// Right Animation
mflipper.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.push_right_in));
mflipper.setOutAnimation(AnimationUtils.loadAnimation(this, R.anim.push_right_out));
count++;
if(count > (imageList.length - 1)) {
count = 0;
}
Bitmap bmp = BitmapFactory.decodeFile(imgpath + imageList[count]);
mImageView.setImageBitmap(bmp);
//Previous View
mflipper.showPrevious();
showToast(imageList[count]);
}
}
return true;
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (mGestureDetector.onTouchEvent(event)) {
return true;
} else {
return false;
}
}
@Override
public boolean onDown(MotionEvent e) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
// TODO Auto-generated method stub
// try {
// if(Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH)
// return false;
//
// // right to left swipe
// if(e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE
// && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
// mflipper.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.push_left_in));
// mflipper.setOutAnimation(AnimationUtils.loadAnimation(this, R.anim.push_left_out));
//
// count--;
//
// if(count < 0) {
// count = imageList.length - 1;
// }
//
// Bitmap bmp = BitmapFactory.decodeFile(imgpath + imageList[count]);
// mImageView.setImageBitmap(bmp);
//
// // Next View
// mflipper.showNext();
// showToast(imageList[count]);
// }
// // left to right swipe
// else if(e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE
// && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
// mflipper.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.push_right_in));
// mflipper.setOutAnimation(AnimationUtils.loadAnimation(this, R.anim.push_right_out));
//
// count++;
//
// if(count > (imageList.length - 1)) {
// count = 0;
// }
//
// Bitmap bmp = BitmapFactory.decodeFile(imgpath + imageList[count]);
// mImageView.setImageBitmap(bmp);
//
// //Previous View
// mflipper.showPrevious();
// showToast(imageList[count]);
// }
// } catch (Exception e) {
// // Nothing
// }
return false;
}현재 구현되어 있는 내용은 viewflipper를 이용한 이미지 뷰어 입니다.
touch 좌우로 다음이미지, 이전이미지를 보여주는 것인데
이것을 onFling을 적용하여 이미지 끌기(?)를 하고 싶습니다.
고수님들의 조언 부탁드립니다.(_ _)




차라리 Launcher 소스를 분석하시는게 빠릅니다.