2014-10-14 7 views
0

스 와이프 순서가 필요한 앱을 제작 중입니다. 예를 들어 먼저 왼쪽으로 스 와이프 한 다음 오른쪽으로 스 와이프 한 다음 위로 스 와이프합니다. 이 조합이 올바른 경우 사용자는 새 활동으로 전송됩니다. 나는 현재이 코드를 시도이 예 http://androidexample.com/Swipe_screen_left__right__top_bottom/index.php?view=article_discription&aid=95&aaid=118스 와이프 제스처 결합하기

를 사용하고 있지만 그 때를 검색합니다 rightleft 이후로 스 와이프 때문에,

public void onSwipe(int direction) { 
    int action = direction; 

    if (action == SimpleGestureFilter.SWIPE_LEFT) { 

     if (action == SimpleGestureFilter.SWIPE_RIGHT) { 

      if (action == SimpleGestureFilter.SWIPE_UP) { 
       //sent to new activity 
       newActivity(); 

      } 

     } 
    } 
} 

답변

0

Aviverma의 대답은 바른 길에 있었다, 그러나 당신이 UP RIGHT LEFT 슬쩍 경우에도 작동합니다. 잘 정의 된 시퀀스가 ​​필요한 경우 배열을 사용하여 이미 완료된 스 와이프와 패턴에서 필요한 다음 스 와이프를 추적해야합니다.

int index = 0; 
int[] pattern = new int[] { SimpleGestureFilter.SWIPE_LEFT, 
          SimpleGestureFilter.SWIPE_RIGHT, 
          SimpleGestureFilter.SWIPE_UP }; 

public void onSwipe(int direction) { 

    if (pattern[index] == direction) { 
     // It's a match! Go onto the next one 
     index++; 
    } else { 
     // Bad swipe, reset the user's swipe progress 
     index = 0; 
    } 

    if (index == pattern.length) { 
     // Reached the end of the pattern! We can perform the action now. 
     // Reset index in case we need this again later 
     index = 0; 
     newActivity(); 
    } 
} 
+0

네 말이 맞아. 나는 결함을 깨달았고 경기를하기 위해 강타를 재설정하려했다. 그러나 당신의 것이 더 최적화 된 방법입니다. 고마워. – zircon

0

이 경우 중첩 된 사람들을 제거 올바른 순서를 얻이 수없는 것 SimpleGestureFilter.SWIPE_RIGHT 안에 onSwipe 방법이 없으면 boolean 값을 사용해보십시오.

편집 : CODE (그냥 당신에게 그것이 작동 수 있는지 아이디어를주기)

boolean RIGHT=false,LEFT=false; 
public void onSwipe(int direction) { 
int action = direction; 

if (action == SimpleGestureFilter.SWIPE_LEFT) { 
    LEFT=true; 
} 

    if (action == SimpleGestureFilter.SWIPE_RIGHT) { 
    RIGHT=true; 
} 

     if (action == SimpleGestureFilter.SWIPE_UP) { 
      if(LEFT && RIGHT) 
      newActivity(); 
} 

} 
+0

감사합니다. – zircon

+0

나는 기쁜 친구 야 !! – Aviverma

+0

질문에 지정된 올바른 순서가 아닌 임의의 순서로 스 와이프 할 수 있습니다. – cdeange

관련 문제