Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 4. Getting the pixels perfect > View hierarchies and rendering

4.2. View hierarchies and rendering

View rendering is an integral aspect of any application that involves a UI. We all love nifty-looking applications, but your application will spend a lot of time drawing its various interface elements. Therefore, it’s important to understand what happens under the hood so you can avoid performance pitfalls. It’s bad if your applications are beautiful, but slow. Though we’ve already introduced and used views, we’re going to expand on their features. Specifically, we’ll explain how they’re organized, how they’re drawn, and what sort of things you should keep an eye on in order to keep the UI snappy.

4.2.1. View hierarchies

We know that views in Android are typically defined in a declarative fashion using XML. XML structures information into trees; all nodes extend and branch from a single root node. It’s no coincidence that Android employs this kind of representation, apart from XML’s general popularity. Internally, the user interface of any Android application is represented as a tree of View objects. This is known as the view hierarchy or view tree. At the root of every view tree—and every application UI—sits a single DecorView. This is an internal framework class that you can’t use directly; it represents the phone window you’re currently looking at. The DecorView itself consists of a single LinearLayout, which branches into two FrameLayouts: one to hold the title section of the currently visible Activity, and one to holds its content (FrameLayouts block out an area on the screen to display a single item). Content here means anything that’s defined in the current activity’s layout XML. To illustrate, let’s examine the XML layout for the MyMovies main screen (res/layout/main.xml):


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free 10-Day Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint