Android: How to use the onDraw method in a class extending Activity?

前端 未结 4 1940
离开以前
离开以前 2021-01-11 17:31

As a beginner, I\'ve been building a simple counter application using a simple layout xml and a class called \'Counter\', which derives (extends) from the class Activity.

4条回答
  •  借酒劲吻你
    2021-01-11 17:55

    I think that you cant use onDraw in class extending an Activity because of using Canvas, you need to create a Custom component extending some View and there handle you action,and what do you need to do that=>

    1.Extend an existing View class or subclass with your own class.

    2.Override some of the methods from the superclass. The superclass methods to override start with ‘on’, for example,onDraw(), onMeasure(), onKeyDown(). This is similar to the‘on’ events in Activity that you override for lifecycle and other functionality hooks.

    3.Use your new extension class. Once completed, your new extension class can be used in place of the view upon which it was based.

提交回复
热议问题