title: Circle Animation to a Drawable inside a Custom View in Android
body: <p>I have a custom view in which I want to load a drawable and then apply circular animation to this drawable:</p>
  <pre><code>class Header @JvmOverloads constructor(
      context: Context,
      attrs: AttributeSet? = null,
      defStyleAttr: Int = 0) : View(context, attrs, defStyleAttr) {
  
      private val backgroundPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
          color = Color.YELLOW
          style = Paint.Style.FILL
      }
  
      private val iconRect = Rect()
  
      private var iconId = 0
  
      private var iconDrawable: Drawable? = ContextCompat.getDrawable(context, R.drawable.ic_app_internal_icon)
  
      init {
          val typedArray = context.obtainStyledAttributes(attrs, R.styleable.Header)
          val backgroundColor = typedArray.getColor(R.styleable.Header_view_color, Color.YELLOW)
  
          iconId = typedArray.getResourceId(R.styleable.Header_drawer_icon, 0)
  
          if (iconId != 0) {
              iconDrawable = VectorDrawableCompat.create(resources, iconId, null)
          }
  
          backgroundPaint.color = backgroundColor
  
          typedArray.recycle()
      }
  
      override fun onDraw(canvas: Canvas?) {
          super.onDraw(canvas)
          drawBackground(canvas)
  
          drawAppIcon(canvas)
      }
  
      private fun drawBackground(canvas: Canvas?) {
          canvas?.drawColor(backgroundPaint.color)        
      }
  
      private fun drawAppIcon(canvas: Canvas?) {
  
          iconRect.top = height / 2 - iconDrawable?.intrinsicHeight!!
          iconRect.left = width / 2 - iconDrawable?.intrinsicWidth!!
          iconRect.right = width / 2
          iconRect.bottom = height/2
  
          iconDrawable?.bounds = iconRect
  
          if (canvas != null) {
              iconDrawable?.draw(canvas)
          }
      }
  
      private fun startAnimation() {
          val animator: ValueAnimator = ValueAnimator.ofFloat(0f, 1440f)
  
          animator.duration = 10 * 1000
          animator.repeatCount = Animation.INFINITE
  
          animator.addUpdateListener { valueAnimator -&gt;
  
              postInvalidate()
          }
          animator.start()
      }
  }
  </code></pre>
  <p>I know that has something to do with <code>animator.addUpdateListener</code>, in there I have to change the coordinates of <code>top</code>, <code>left</code>, <code>right</code> and <code>bottom</code> of the drawableRect. But I don't know how to do it.</p>
  <p>the required result is like:</p>
  <p><a href="https://i.stack.imgur.com/00p5L.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/00p5L.gif" alt="enter image description here" /></a>
  Any help please?</p>