A (175)

(Tuis.) #1
CHAPTER 4: Introduction to XML: Defining an Android App, Its Design, and Constants 105

Thus, thanks to the xmlns:android URL definition parameter, the android:width=“match_parent”
parameter is actually short-hand for a http://schemas.android.com/apk/res/android:width="match_parent"
parameter.


The same logic applies to the second xmlns:tools parameter and the tools:context=“.MainActivity”
parameter at the end of the parent tag, also shown in Figure 4-1. These XML
constructs (tags and parameters) are more complex, lower-level operating-system–related definitions
such as the one here that sets the Context object for the RelativeLayout UI definition to the
MainActivity Activity class, which Eclipse ADT created for you in Chapter 2 using the New Android
Application Project series of dialogs.


As you can see here, Android OS really has two XML naming schemas (language definitions), in two
different software repositories. The Android Package (apk) naming schema was designed for high-
level (design-oriented usage) XML, and is at schemas.android.com/apk. It is also the one you will
be using 95% of the time in your Android application development, and the one I will be covering
throughout this book.


The Android Tools (tools) naming schema was designed to provide low-level (OS-related usage)
XML, and is at schemas.android.com/tools. You can use it to do things such as declare a Context
object using XML. You will learn more about Context objects in the next chapter when I cover Java
programming concepts and structures as well as throughout the book as we use Context objects.


XML Syntax: Containers, Brackets, and Nesting


There are two ways to code (or to mark up, to be more precise) any XML tag, and which markup
approach you use depends upon whether that tag is going to have any children (nested tags) or not.
Attributes, also known as parameters, are inside each tag, and configure the tag and what it will do,
but should not be considered “children” of the tag. Attributes that specify values or references will
use quotation marks to do this, such as the android:text=“data value” parameter shown shortly.


If an XML tag is a parent tag (this is, it has “nested” or child tags inside of it), it is said to be a
“container,” just like the XML file itself is the container for the entire XML construct, which in
Android is generally a definition of one type or another, as you will see throughout this chapter, as
well as throughout the rest of this book.


Fortunately, our HelloUniverse bootstrap UI layout design, shown in Figure 4-1, shows both of these
types of bracketing treatments, so I can simply describe the usage here and you can observe it in
the screen shot (or in Eclipse ADT, if you have it running and on your computer workstation screen,
which I am hoping you do).


Since the UI element, which defines a Text UI element on the screen, as you may have
guessed, has no children, and has parameters configuring its width, height, and text content, this tag
is opened using the character sequence.
So, with parameters inside of this tag, it would look something like this:



The XML for this child tag, which is shown in Figure 4-1, uses indentation, for easy parameter
views, as well as actual Android constants, which you’ll learn about in the next chapter covering
Java, as well as Java String references to a text data value, which you’ll learn about soon in the

Free download pdf