Problems for implementation:
Code cleanliness - Doing anything more than the basic layouts in your code can become very dirty, very fast.
Reusing code -> Its extremely easy to inflate an XML layout into a specified view with one or two lines of code
Code performance β Creating the objects necessary for compilation in the code leads to unnecessary garbage collection. According to Android Designing for Performance, "Avoid creating short-term temporary objects if you can."
Attribute Availability β Defining Views in an XML Layout provides attributes that are not always accessible by object methods.
Possible disadvantages:
It will take longer to create the XML layout and define the layout in the code, especially if there is only one or two interface elements that need to be changed.
After thinking about what I want to achieve, it makes sense for me to use XML layouts for changing dynamic changes. It would be more than just a few lines of code to execute my layout changes without using XML layouts.
Now you can decide according to your requirements.
source share