title: Custom view animation with invalidate does not trigger sometimes onDraw()
body: <p>I am writing a custom view where I draw myself to the canvas in the onDraw(Canvas canvas) method. 
  My idea is to also animate the view as soon as it becomes visible by using an ObjectAnimator and a setter for a particular variable in my view. Class looks as follows:</p>
  
  <pre><code>public DrawView(Context context, AttributeSet attrs) {
      super(context, attrs);
      init(context, attrs, -1);
  }
  
  public DrawView(Context context, AttributeSet attrs, int defStyleAttr) {
      super(context, attrs, defStyleAttr);
      init(context, attrs, defStyleAttr);
  }
  
  @TargetApi(Build.VERSION_CODES.LOLLIPOP)
  public DrawView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
      super(context, attrs, defStyleAttr, defStyleRes);
      init(context, attrs, defStyleAttr);
  }
  
  private void init(final Context context, AttributeSet attrs, int defStyleAttr) {
  
      anim = ObjectAnimator.ofInt(this, PROGRESS, 0, 100);
      anim.setDuration(animDuration);
  
      if (getVisibility() == VISIBLE) {
          getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
              @Override
              public boolean onPreDraw() {
                  getViewTreeObserver().removeOnPreDrawListener(this);
  
  
                  animate();
  
  
                  return true;
              }
          });
      }
  
  @Override
  protected void onDraw(Canvas canvas) {
      super.onDraw(canvas);
      // Draw something here using progress
  }
  
  protected void setProgress(final int pathProgressParam) {
          // Re-draw
          invalidate();
      }
  
  }
  </code></pre>
  
  <p>When triggering the animation, the "setProgress" method is called properly, and the View gets invalidated to force a re-draw with the new value for my progress field. 
  The problem comes when sometimes, let's say 30% of the times, the onDraw method is not called even though the View gets marked as "dirty", and only the very last frame is drawn, which kinda defeats the purpose of the animation.</p>
  
  <p>I do not know whether there is any better step in the drawing cycle to trigger the animation, of if I should trigger it from somewhere else as well, but it seems as invalidate() is not enough. I have also looked at how Android guys perform property animations, but unfortunately the methods they used are hidden.
  Btw, I have used the same idea as Romain Guy did here: <a href="https://github.com/romainguy/road-trip" rel="nofollow">https://github.com/romainguy/road-trip</a></p>