Android Programming The Big Nerd Ranch Guide, 3rd Edition

(Brent) #1

Chapter 7  UI Fragments and the Fragment Manager


138

Note that while activity_crime.xml consists solely of a container view for a single fragment, an
activity’s layout can be more complex and define multiple container views as well as widgets of its
own.


You can preview your layout file or run CriminalIntent to check your code. You will see an empty
FrameLayout below a toolbar containing the text CriminalIntent (Figure 7.13). (If the preview window
does not render the screen correctly, or you see errors, build the project by selecting Build → Rebuild
Project. If that still does not work correctly, run the app on your emulator or device. As of this writing,
the preview window can be finicky.)


Figure 7.13  An empty FrameLayout


The FrameLayout is empty because the CrimeActivity is not yet hosting a fragment. Later, you
will write code that puts a fragment’s view inside this FrameLayout. But first, you need to create a
fragment.


(The toolbar at the top of your app is included automatically because of the way you configured your
activity. You will learn more about the toolbar in Chapter 13.)

Free download pdf