An android app will often comprise multiple destinations. For example, an app for an online store may have separate destinations for the homepage, product pages, and checkout. Each destination will likely need a different user interface. In Android programming, user interfaces are designed by creating XML layout files. A layout file contains all the text, images, and buttons (collectively referred to as widgets) required to display content to the user and handle user interactions. In this tutorial, we will explore how to create layout files for the different areas in your app and use buttons to allow the user to navigate from one destination to another.
When you start a new project, Android Studio will often create an XML file called activity_main.xml. The activity_main.xml layout is the default layout for the app and will be displayed first when the app loads (unless advised otherwise). To create a new layout file for another area of the app, navigate through Project > app > res then right-click the layout folder. Next, select New > Layout resource file.
In the New Resource File window, enter the file name for the new layout (e.g. 'second_layout') then press OK. The other options can be left at their default values in this example.
Android Studio will now create and open a new file called second_layout.xml (or the file name you entered). The file can be found in the layout folder alongside the activity_main.xml file.