2011-05-16 2 views
2

간단한 질문 일 수도 있지만 해결책을 찾을 수 없습니다.문제를 해결하는 방법 업데이트/새로 고침을하는 동안 - 애니메이션을 표시 하시겠습니까?

일부 콘텐츠를 새로 고치거나 업데이트하기위한 버튼이 있습니다. "새로 고침"단추. 이 버튼의 배경에는 이미지가 있습니다. 내 콘텐츠가 업데이트되는 동안이 이미지에 대한 회전 애니메이션을 설정하고 싶습니다. 그러나 나는 약간의 문제가 있습니다. 첫째, 내 컨텐츠가 업데이트되었고 애니메이션을 볼 수있는 것보다 : 여기 내 코드가 있습니다.

Timer myTimer; 
    public void timerS() 
    { 
     myTimer = new Timer(); 
     myTimer.schedule(new TimerTask() { 
      @Override 
      public void run() { 
       TimerMethod(); 
      } 
     }, 0, 100); 
    } 
    private void TimerMethod() 
    { 
     this.runOnUiThread(Timer_Tick); 
    } 

    private Runnable Timer_Tick = new Runnable() { 
     public void run() { 
     // drawMatrix(); 
      animation(); 
      seconds++; 
     } 

    }; 
    int degree =60; 
    int oneClick=1; 
    public int nowUpdated = 0; 
     public void animation() 
     { 
     int currentRotation = 0; 
      RotateAnimation anim = new RotateAnimation(currentRotation, (360*4), 
        Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,0.5f); 
      currentRotation = (currentRotation + 45) % 360; 

      anim.setInterpolator(new LinearInterpolator()); 
      anim.setDuration(10000); 
      anim.setFillEnabled(true); 

      anim.setFillAfter(true); 
      refresh.startAnimation(anim); 
     } 

나는 이것을 위해 타이머를 사용하려고했습니다. 첫 번째 예제는 drawMatrix와 함께했지만 이미지 크기가 문제가 될 수 없습니다. 이미지가 회전하면 애니메이션이 매우 커집니다. 이미지 크기 32x32 ..하지만 업데이트를 클릭하면 - 이미지 크기가 64x64라고 생각합니다. 와 무승부 행렬이 다음 코드를 수정할 수 없습니다 : 누군가가 나를 도울 수 있다면

public void drawMatrix() 
    { 
     if(nowUpdated==1) 
     { 
     Matrix mat = new Matrix(); 
     degree=degree+45; 
     mat.postRotate(degree); 
     Bitmap source = BitmapFactory.decodeResource(getResources(),R.drawable.refresh); 

     Bitmap a = Bitmap.createBitmap(source, 0, 0, 32 , 32, mat, true); 
     Drawable d =new BitmapDrawable(a); 
     refresh.setBackgroundDrawable(d); 
     } 
    } 

하십시오 - 어떻게 처음으로 내 코드 또는 두 번째 해결 방법을 가르쳐주십시오. 감사합니다.

답변

1

채팅에서 설명한대로 : AsyncTask를 사용하여 업데이트 처리 (doInBackground()) 및 실제 처리 (call publishProgress() 호출)를 시작하기 전에 AsyncTask 메서드 onProgressUpdate를 호출합니다. 오버라이드) 그리고 거기에서 애니메이션을 시작하십시오. - 후자의 단계는 onProgressUpdate가 UI 스레드를 처리 할 수 ​​있기 때문에 필요합니다. doInBackground는 (UI 스레드에서 실행되지 않기 때문에) 할 수 없습니다.

+0

yeeeeeep을 Ready4Android

건배, : D (4more) – Peter

+0

Ready4Android, 당신은 scype 로그인 할 수 있습니까? – Peter

+0

안녕하세요. 나에게 메시지를 쓸 수 있습니까? – Peter

관련 문제