Why onDraw is not called after invalidate()?

后端 未结 4 1385
不知归路
不知归路 2020-11-29 01:46

I have found many posts on stackoverflow but I still cannot solve my problem. Here is my code piece:

public class MyView extends RelativeLayout {

Button b1;         


        
4条回答
  •  一向
    一向 (楼主)
    2020-11-29 02:21

    You need to call setWillNotDraw(false); in order for your onDraw method to be called:

    private void init() {
      setWillNotDraw(false);
      ...
    }
    

提交回复
热议问题