search

Home  >  Q&A  >  body text

android 为什么自定义的view不能显示LayoutInflator.inflate方法加载的布局,

我的那个方法写在构造方法里面

PHP中文网PHP中文网2803 days ago672

reply all(4)I'll reply

  • 伊谢尔伦

    伊谢尔伦2017-04-17 17:25:23

    You should just put the code that loads the layout into the first constructor.

    reply
    0
  • 怪我咯

    怪我咯2017-04-17 17:25:23

    Can a custom view load the layout like this?
    Customizing the view is to write the custom control into the layout file or code. The construction method with two parameters in the picture is to write the control in XML

    reply
    0
  • 天蓬老师

    天蓬老师2017-04-17 17:25:23

    1. The construction of a parameter is used in the code. The structure of the two parameters is used in xml

    2. Let’s talk about the inflate method.

    It goes without saying that you know the first parameter. It’s the layout file,

    The second parameter is to set the parent layout of this View. The LayoutParams type of the view obtained by inflate will become the LayoutParams type of the parent layout

    When the third parameter is true, the view obtained by inflate will replace the ViewGroup passed in the second parameter, otherwise it will not replace it

    reply
    0
  • ringa_lee

    ringa_lee2017-04-17 17:25:23

    Just replace the second parameter null with this

    reply
    0
  • Cancelreply