From personal experience, I would say that the difference in performance between them is insignificant. However, use XML for a pure reason, to make it more convenient. Thus, you can create your own layouts in such a way that they can be easily recognized and edited by other potential developers (or even later).
Everything that you can do the layout in the code, you can do in XML, and if you need to add additional functions, you can still reference the elements in XML in the code using findViewById(R.id.ELEMENT_NAME);
source share