Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7588759
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:00:09+00:00 2026-05-30T20:00:09+00:00

For my activity i use 3 custom views stacked. the lower one is a

  • 0

For my activity i use 3 custom views stacked.
the lower one is a SurfaceView fullscreen, the middle one is derived from GridView and overrides onDraw to add custom graphic.

The top one is derived directly from View, sits in a corner of the screen and act as a knob to control the others two views (this is the problematic view).

to add a custom animation to this view, i used this pattern:

public class StubKnobView extends View{

    private Drawable knob;
    private Point knobPos;
    private float rotation;
    private boolean needsToMove;

    public void moveKnob(){
            /* ...various calculations... */
            this.needsToMove=true;
            invalidate();   //to notify the intention to start animation
    }

    private void updateAnimation(){
        /* ........... */
        this.needsToMove= !animationComplete;
        invalidate();        
    }

    @Override
    protected void onDraw(Canvas canvas) {
        int saveCount=canvas.getSaveCount();
        canvas.save();
        canvas.rotate(this.rotation, this.knobPos.x, this.knobPos.y );
        this.knob.draw(canvas);
        canvas.restoreToCount(saveCount);
        if(this.needsToMove){
            updateAnimation();
        }
    }
}

ideally, if there is an animation pending, after each drawing cycle the view should auto invalidate.

right now this doesn’t work, to force the animation i have to touch the screen to cause a onDraw cycle.
Using “show screen updates” of Dev tools I see that no screen invalidate/update cycle happen , apart when i click the screen.
specifying the dirty rect also ha no effect.

So, any idea where to look to know why this invalidate/draw cycle does not work the way is intended?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T20:00:11+00:00Added an answer on May 30, 2026 at 8:00 pm

    Try something like this with a private class in your View. The idea is not to call invalidate() from within onDraw(). Instead, post it on the running queue. Instantiate the private class in your View constructor and then just call animateKnob.start() when you want the animation. The onDraw() can then just focus on drawing.

    public void moveKnob(){
    
      // update the state to draw... KnobPos, rotation
      invalidate()
    
    }
    
    
    private class AnimateKnob{
       public void start(){
          // Do some calculations if necessary 
          // Start the animation
          MyView.this.post( new Runnable() {
            stepAnimation()
          });
       }
    
       public void stepAnimation(){
         // update the animation, maybe use an interpolator.
         // Here you could also determine if the animation is complete or not
    
         MyView.this.moveKnob();
    
         if( !animationComplete ){
           // Call it again
           MyView.this.post( new Runnable() {
              stepAnimation()
           });
         }
    
       } 
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created one gridview and use custom adapter for that. I added two
I haven't found any references to apps that use a custom activity indicator --
I was implementing a ListView activity with custom drawn views and had the following
In my Android activity, I create a custom view that extends SurfaceView (using MonoDroid
I have a listview extends Activity and use custom adapter because I want icon
My linear layout has two views: Custom View that display dynamic stuff One button
In my Activity I use multiple AsyncTask classes. How to cancel AsyncTask when Activity
i need to use the animate property for a less than usual activity. i
I have a custom view controller that implements the from UITableViewDataSource and UITableViewDelegate protocols.
I want to dynamically set the contentView in my activity. Because one time i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.