Chapter 9. Building simple Android views

 

This chapter covers

  • Android resources
  • Creating layout resources in the Designer and by editing the source
  • Adding images to support multiple screen densities
  • Creating views using activities
  • The activity lifecycle

In the previous two chapters we built the model and view-model layers for our two apps. Now it’s time to turn our attention to the view layer. This layer uses platform-specific code, so we’re going to look at it platform by platform—in this chapter and the next, we’ll look at Android (figure 9.1), followed by iOS in chapters 11 and 12.

Figure 9.1. The view layer in an MVVM app is written in platform-specific code.

We’ll start here by looking at how to build an Android UI. Then we’ll build the UI for SquareRt. In the next chapter we’ll look at Countr, and you’ll see a slightly more advanced UI that uses recycler views to show lists of data, menus, and navigation.

When building any UI-based app on any platform, you need to understand the concepts behind the app structure. Each platform has a different structure. On Android you structure your apps using activities—single screens in your app that each represent a single focused thing that a user would want to do. When building Android apps using MVVM, an activity is the same as a view.

9.1. Building Android UIs

9.2. Creating the layout file for the SquareRt UI

9.3. Building the SquareRt view

Summary

sitemap