开发者

how to fix issue While updated/refreshed - show animation?

simple question maybe but can't find solution.

I have button for refresh/update some contents . Button called "refresh". In background of this button - i have image. I want to set rotated animation for this image while my content updated . But i have some problem : First - my content updated and only than i can see animation : here is my code :

 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);
        }

i tried to use timer for this. First my example was with drawMatrix - but there i cant fix issue with size of image.. When my image is rotated - Animation is very big. Size of image 32x32.. but when click for updated - i think size of image is 64x64. and can't fix this Here code for draw matrix :

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);
    开发者_Python百科     Drawable d =new BitmapDrawable(a);
         refresh.setBackgroundDrawable(d);
        } 
     }

please if anyone can help me - please tell me how to fix first my code or second. Regards Peter.


as discussed in chat: use an AsyncTask to do your update processing (in doInBackground() ) and before starting with the actual processing - call publishProgress() - that will call the AsyncTask method onProgressUpdate (which you'll have to override) and start your animation there :) - the latter step is necessary, because onProgressUpdate can do UI thread stuff - doInBackground can't (because it's not running on the UI thread).

Cheers,

Ready4Android

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜