android: onDraw is called constantly

前端 未结 2 374
野性不改
野性不改 2021-01-21 11:50

I have a problem with a custom button. onDraw() gets called again and again, and I can\'t figure out why.

public class CircleButton extends Button {

    static          


        
相关标签:
2条回答
  • 2021-01-21 12:15

    Change the drawableStateChanged() method:

    1. Don't call invalidate
    2. Call super.drawableStateChanged().
    0 讨论(0)
  • 2021-01-21 12:19

    Sorry, dumb failure:

    this.getDefaultBitmap() had a setBackgroundColor(0x00000000); call in it which retriggered the onDraw.

    So kind of a recursion:

    onDraw() -> getDefaultBitmap() -> setBackgroundColor() -> onDraw

    0 讨论(0)
提交回复
热议问题