2012-10-27 2 views
2

안드로이드에서는 SurfaceView에 회전/뒤집기 동전을 놓는 방법을 제공합니다. 애니메이션을 사용하고 뒤집기 동전을 ImageView에 표시하는 것은 매우 쉽습니다. 그러나 나는 동일한 부드러움을 가지고 SurfaceView에 이것을 요구합니다. ImageView에서 플립 애니메이션을 제공 할 수있는 방법이 있습니까? 매 순간 콘텐츠를 꺼내서 SurfaceView에 계속 그려야합니다.안드로이드에서 안드로이드가 부드럽게 회전합니다. 사용자와 관련하여

답변

2

Matrix 클래스를 사용하여 비트 맵 그리기에서 이러한 작업을 수행 할 수 있습니다.

뭔가 아래

Paint paint = new Paint(); 
    paint.setAntiAlias(true); 
    Matrix needleTransMatrix = new Matrix(); 
    needleTransMatrix.postRotate(rotationAngle,needleImage.getWidth()/2,needleImage.getHeight()); 
    needleTransMatrix.postTranslate(centerX+METER_OFFSET-needleImage.getWidth()/2, centerY-needleImage.getHeight()); 

    Matrix dialTransMatrix = new Matrix(); 
    dialTransMatrix.postRotate(rotationAngle,dialImage.getWidth()/2,dialImage.getHeight()/2); 
    dialTransMatrix.postTranslate(METER_OFFSET,0); 

    canvas.drawBitmap(bgImage, METER_OFFSET, 0, paint); 
    canvas.drawBitmap(dialImage, dialTransMatrix, paint); 
    canvas.drawBitmap(needleImage, needleTransMatrix, paint); 

처럼 어느 대해 내가이 scalling에 의해 한 번에 하나의 순간을 가져올 수 있습니다 매트릭스를 사용하여 시도에 대한

private class AnimationThread extends Thread{ 

    private boolean isRunning = true; 
    private int destinationNeedlePosition = NEEDLE_POSITION_ENQURIES; 

    public AnimationThread(int destinationNeedlePosition) { 
     this.destinationNeedlePosition = destinationNeedlePosition; 
    } 

    public void cancelAnimation(){ 
     isRunning = false; 
    } 

    @Override 
    public void run() { 

     int destinationAngle = destinationNeedlePosition *45; 

     while(isRunning && destinationAngle != rotationAngle){ 
      if(destinationAngle > rotationAngle) 
       rotationAngle++; 
      else 
       rotationAngle--; 
      postInvalidate(); 
      try { 
       sleep(10); 
      } catch (InterruptedException e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } 
     } 
    } 

} 
+0

넵를 이야기하고 도면 스레드입니다 .. 그것은 매끄러운 뒤집기 느낌을주지 않을 것이다! – pvn

+0

당신은 하나의 위치에서 다른 위치로의 전환을 수행하고 위치를 보간 할 스레드를 생성해야합니다. 이 방법으로 미터의 바늘을 회전시킨 것과 같은 일입니다. –

+0

왜 2 개의 행렬을 사용하고 있습니까? – pvn

관련 문제