I wouldn't suggest having a handler sitting there trying to post messages to
itself as fast as possible.  You are just writing code that sits there
consuming every bit of CPU it can get for no useful reason.  Either use
postMessageDelayed/AtTime() to actually have controlled timing, or just do
invalidate() each time you draw to tie to the frame rate.

That said, if you are getting glitches of significantly less than 60fps than
you simply have performance issues.  Look at the log to see if you are GCing
a lot (hint: you absolutely do not want to be creating temporary objects in
your drawing path), and use the profiling to see what is taking a long time
in your code.

On Thu, Apr 7, 2011 at 11:29 PM, Numeron <numeronreac...@gmail.com> wrote:

> Im having trouble smoothing out a hand made animation, specifically the
> logo on my site at www.users.on.net/~rossn
>
> The spinning sections of the logo are redrawn every frame rather a pair of
> rotating images, because rotating is slow and sometimes looks bad with poor
> rotation algorithms on other graphics libraries - the same code has been
> used over and over with a few different libraries now...
>
> I currently have a Handler which is sending a reoccuring repaint call to
> recalculate and redraw the lines. For the most part this works, but
> occasionally it becomes a bit choppy. I assume this is because other jobs
> are being processed by the same looper? Garbach collection maybe? Is it best
> to try and pull the redraw loop out into a seperate thread/Looper? I should
> note that Im not too keen on doing that because I'll be using the same setup
> later with game animations - the world will need to be updated between
> screen refreshes making syncing two threads a lot of hard work when one
> thread will do.
>
> Anyway here is code, with unrelated stuff removed and some names changed...
> The MyView class onDraw(), which is not shown, recalculates and redraws the
> lines of the logo on the view.
>
> public class MyClass extends Activity{
>
>   MyView view;
>
>   @Override
>   public void onCreate(Bundle savedInstanceState){
>     super.onCreate(savedInstanceState);
>     requestWindowFeature(Window.FEATURE_NO_TITLE);
>     getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
> WindowManager.LayoutParams.FLAG_FULLSCREEN);
>
>     view = new MyView(this);
>     this.setContentView(view);
>
>     new RefreshHandler().run();
>   }
>
>   class RefreshHandler extends Handler implements Runnable{
>     @Override
>     public void run(){
>       view.invalidate();
>       this.post(this);
>     }
>   }
>
> }
>
>
> -Numeron
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en




-- 
Dianne Hackborn
Android framework engineer
hack...@android.com

Note: please don't send private questions to me, as I don't have time to
provide private support, and so won't reply to such e-mails.  All such
questions should be posted on public forums, where I and others can see and
answer them.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to