Android Custom Layout - onDraw() never gets called

后端 未结 2 670
梦如初夏
梦如初夏 2020-11-29 23:55
public class MainActivity extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
                 


        
相关标签:
2条回答
  • 2020-11-30 00:24

    If you want that the canvas is be re-draw call invalidate(), and the method onDraw() will be re-executed

    0 讨论(0)
  • 2020-11-30 00:30

    By default, onDraw() isn't called for ViewGroup objects. Instead, you can override dispatchDraw().

    Alternatively, you can enable ViewGroup drawing by calling setWillNotDraw(false) in your TableView constructor.

    EDIT:

    For #2: - Initialize it in the constructor, then just call rect.set() in your onLayout() method.

    For #3: - Yes, as far as I'm aware the super call will handle it, you shouldn't have to handle that unless you need to customize the way the children are drawn.

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