2014-09-30 3 views
1

레이아웃에서 scrollview를 사용하고 있습니다. 스크롤 이벤트가있을 때 애니메이션을 적용하고 스크롤이 끝나면 애니메이션을 중단해야합니다.어쨌든 스크롤 및 스크롤 이벤트를 감지 할 수 있습니까?

나는 scrollview를 확인했지만 이러한 이벤트를 제공하지 못하는 것 같습니다. 제스처 탐지기를 사용해야합니까?

도와주세요.

감사합니다, 스 네하

답변

0

내 문제가 해결되었습니다! :)

svMovieDetails.setOnTouchListener (새 View.OnTouchListener() {

 @Override 
     public boolean onTouch(View v, MotionEvent event) { 
      switch (event.getAction()) { 
       case MotionEvent.ACTION_SCROLL: 
       case MotionEvent.ACTION_MOVE: 
        Log.e("SCROLL", "ACTION_SCROLL"); 
        break; 
       case MotionEvent.ACTION_DOWN: 
        Log.e("SCROLL", "ACTION_DOWN"); 
        break; 
       case MotionEvent.ACTION_CANCEL: 
       case MotionEvent.ACTION_UP: 
        Log.e("SCROLL", "SCROLL_STOP"); 
        break; 
      } 
      return false; 
     } 
    }); 
0
import android.view.GestureDetector; 
import android.view.GestureDetector.SimpleOnGestureListener; 
import android.view.MotionEvent; 
import android.view.View; 
import android.view.View.OnTouchListener; 

public class OnSwipeTouchListener implements OnTouchListener { 

    private final GestureDetector gestureDetector; 

    public OnSwipeTouchListener (Context ctx){ 
     gestureDetector = new GestureDetector(ctx, new GestureListener()); 
    } 

    private final class GestureListener extends SimpleOnGestureListener { 

     private static final int SWIPE_THRESHOLD = 100; 
     private static final int SWIPE_VELOCITY_THRESHOLD = 100; 

     @Override 
     public boolean onDown(MotionEvent e) { 
      return true; 
     } 

     @Override 
     public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { 
      boolean result = false; 
      try { 
       float diffY = e2.getY() - e1.getY(); 
       float diffX = e2.getX() - e1.getX(); 
       if (Math.abs(diffX) > Math.abs(diffY)) { 
        if (Math.abs(diffX) > SWIPE_THRESHOLD && Math.abs(velocityX) > SWIPE_VELOCITY_THRESHOLD) { 
         if (diffX > 0) { 
          onSwipeRight(); 
         } else { 
          onSwipeLeft(); 
         } 
        } 
        result = true; 
       } 
       else if (Math.abs(diffY) > SWIPE_THRESHOLD && Math.abs(velocityY) > SWIPE_VELOCITY_THRESHOLD) { 
         if (diffY > 0) { 
          onSwipeBottom(); 
         } else { 
          onSwipeTop(); 
         } 
        } 
        result = true; 

      } catch (Exception exception) { 
       exception.printStackTrace(); 
      } 
      return result; 
     } 
    } 

    public void onSwipeRight() { 
    } 

    public void onSwipeLeft() { 
    } 

    public void onSwipeTop() { 
    } 

    public void onSwipeBottom() { 
    } 
} 

당신은 ScrollView을 확장 할 수 있습니다 당신은 내가 this 토론

0

에서 얻을이 하나 도움이 될, 스크롤을 얻을 수

@Override 
protected void onScrollChanged(int l, int t, int oldl, int oldt) 

무시할 수 있습니다. 활동/단편에서이 값을 얻으려면 수신기를 정의 할 수도 있습니다.

+0

감사합니다.하지만 스크롤이 발생하고 또는 당신이 때 스크롤 유휴 상태를 고려할 수 있다고 생각? – Neha

+0

을 종료하는 경우는 어떻게해야합니까 방법 'oldt == t'와'oldl == l'. 일어나고 있다면 값은 달라질 것입니다 – Blackbelt

관련 문제