Design + Code an Android App from Scratch
This video shows how to add a Fragment to XML directly. In the first step, create an activity and its layout file. Create a class that extends the android.app.Fragment or android.support.v4.Fragment and override the onCreateView method. Define a layout for the fragment that contains all the UI widgets which you want to display inside the Fragment. Link this layout inside onCreateView using a Layout Inflater. Create the fragment tag in the XML layout of the Activity and specify the class attribute to point to the Java class file of the Fragment that you created earlier.