2012-11-09 1 views
0

회전시키고 자하는 원이 있습니다. 제스처, 특히 onScroll 메서드를 처리하기 위해 SimpleOnGestureListener를 사용하고 있습니다.SimpleOnGestureListener를 사용한 안드로이드 부드러운 회전

 @Override 
    public boolean onScroll(MotionEvent e1, MotionEvent e2, 
      float distanceX, float distanceY) { 

     float lWidth = e1.getX() - centeralPointX; 
     float lHeight = e1.getY() - centeralPointY; 
     float lRadius = FloatMath.sqrt(lWidth * lWidth + lHeight * lHeight); 

     if ((lRadius <= bigCircleRadius) && (lRadius >= smallCircleRadius)) { 

      mLastAngle = (float) (Math.atan(lHeight/lWidth) * 180/Math.PI) 
        + step/2; 

      float currWidth = e2.getX() - centeralPointX; 
      float currHeight = e2.getY() - centeralPointY; 
      mCurrentAngle = (float) (Math.atan(currHeight/currWidth) * 180/Math.PI) 
        + step/2; 

      mAngle = mLastAngle - mCurrentAngle; 
      mLastAngle = mCurrentAngle; 

      // show angles 
      TextView lastANGLE, endANGLE, ANGLE; 
      lastANGLE = (TextView) findViewById(R.id.currentAngle); 
      lastANGLE.setText("last " + mLastAngle); 
      endANGLE = (TextView) findViewById(R.id.endAngle); 
      ANGLE = (TextView) findViewById(R.id.angle); 

      endANGLE.setText("current " + mCurrentAngle); 
      ANGLE.setText("ANGLE " + mAngle); 

      rotation = (float) (-mAngle - step/2); 
      if (rotate != null && !rotate.hasEnded()) { 
       rotate.cancel(); 
       rotate.reset(); 
      } 
      rotate = RotateCircle(radius, radius); 
      words_layout.startAnimation(rotate); 
      return true; 
     } else 
      return false; 
    } 

하지만 제대로 작동하지 않습니다. 그 원이 부드럽게 회전하기를 원하지만 그렇지 않습니다. 어떻게해야합니까? onFling 메서드를 사용하려고했지만 이동이 끝난 후 내 원을 회전합니다. 그러나 나는 운동 중에 그것을 회전시켜야한다.

답변

1

당신은이 같은 View.onTouchEvent(MotionEvent e)을 재정의 할 시도 할 수 있습니다 :

@Override 
public boolean onTouchEvent(MotionEvent event) { 
    switch(event.getAction()) { 
     case MotionEvent.ACTION_DOWN: 
      lastEventX = e.getX(); 
      lastEventY = e.getY(); 
      return true; 

     case MotionEvent.ACTION_MOVE: 
      // put your code to rotate here using lastEventX and lastEventY instead of e1.getX() and e1.getY() 
      return true; 
    } 
    return super.onTouchEvent(MotionEvent event); 
} 
1

또 다시 같은 3 개체에 대한, 같이 findViewById() onScroll가 트리거됩니다 때마다 호출하지 마십시오.