You now have two distinct approaches to building a UI. You can do the whole job in code or you can create an XML layout.
In practice it is usually easier to use the Android Studio designer to generate the XML file for you.
You can however mix the two approaches and change a UI "on the fly". For example you can load a UI by implicitly or explicitly inflating an XML file and then writing code to create and add other widgets or even remove View objects from the layout.
To remove View object you simply use the removeView or removeViewAt methods of the ViewGroup object.
There are other UI components such as menus that the designer doesn't support. In this case you have to work with the XML or create the UI in code. This means you do need to know the inner workings of the View hierarchy even though the designer is the easiest way to create a UI.
Summary
All of the UI components are derived from the View class.
An Activity can host and display a single instance of the View class set by one of its setContentView methods.
You can create instances of View objects in code and set them to be displayed by the Activity.
A Layout or ViewGroup object is a View object that can contain many View objects so creating a sophisticated layout that the Activity can display.
Each Layout has its associated LayoutParam class which is used by each View object it contains to control how it treats it within the layout.
You generally have to create an instance of the LayoutParam class, set the parameters you want to determine and then set the instance as the LayoutParam of each View object that needs to use it via the setLayoutParams method.
The use of Layout containers results in a View hierarchy i.e. a hierarchy of View objects which are displayed by the Activity.
You can also code the View hierarchy using XML. Each XML tag corresponds to a View object and they are nested to define the hierarchy. The properties of the objects are set within the XML as attributes. Layout properties are treated in the same way but with layout_ as a prefix.
When the time comes for the View hierarchy to be assigned to the Activity, the XML file is converted into a nested set of View objects by the use of an inflater method. This simply reads the XML and converts each tag to an object and sets the objects properties.
To find particular View objects in an inflated hierarchy the usual approach is to assign an id and use the findViewById method.
What more is there to learn?
Next we need to look at menus and some other interesting UI components.
Android Programming In Java: Starting With an App Third Edition