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
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
You should just put the code that loads the layout into the first constructor.
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
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
Just replace the second parameter null with this