How to add custom view to the layout?

后端 未结 7 1698
灰色年华
灰色年华 2020-11-30 07:35

I have a GraphicsView class that extends from the View class and I want to add this GraphicsView class to the main layout in my projec

7条回答
  •  时光取名叫无心
    2020-11-30 08:15

    Because your custom View is an inner class in your Activity the java compiler will output the name ActivityName$GraphicsView for that class. You can't use that name directly as the View name in the xml layout because of the $ character but you can do it like this:

     
    

    where ActivityName is the name of the activity where your GraphicsView class is declared.

提交回复
热议问题