6.4.4. activity_main.xml

The activity_main.xml layout for this app’s MainActivity contains only the CannonGameFragment. To add this Fragment to the layout:

1. Open activity_main.xml in the Graphical Layout editor, then follow the steps in Section 2.5.2 to switch from a FrameLayout to a RelativeLayout.

2. From the Palette’s Layouts section, drag a Fragment onto the design area or onto the RelativeLayout node in the Outline window.

3. The preceding step displays the Choose Fragment Class dialog. Click Create New... to display the New Java Class dialog.

4. Enter CannonGameFragment in the dialog’s Name field, change the Superclass field’s value to android.app.Fragment and click Finish to create the class. The IDE opens the Java file for the class, ...

Get Android™ How to Program, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.