A (175)

(Tuis.) #1

180 CHAPTER 6: Android Screen Design: Writing to the Display Using Activity and View


Next, we will create a UI design to display our Galaxy object characteristics (data values) using a
LinearLayout class (ViewGroup subclass) as our layout container. Inside of the UI, we will use View
subclass that we’ve been using so far in the book, the TextView class, to create an impressive
Galaxy Information Screen UI design.


Using LinearLayout: Creating Linear UI Designs


Since we’re going to cover the RelativeLayout class in greater detail in Chapter 7, I want to take
the opportunity to teach you about the LinearLayout class in this chapter, so that we can focus on
the advanced layout container classes in Chapter 8 regarding UI layout classes. To see how easy
it can be to edit a layout container class reference using the parent tag in XML, change the word
“Relative” to “Linear” in the opening and closing tags in the current /res/layout/activity_main.xml
UI definition file, shown in Figure 6-11.


Figure 6-11. Changing a parent tag to a parent tag and reposition parameters


To make room for some of the other child tags we will be adding, I also put the tools:context
parameter next to (but after, as the xmlns:tools parameter defines the tools: prefix) the xmlns:tools
parameter, and also placed the android:layout_width and android:layout_height parameters on
the same line as well, to make the mark-up more dense and save us some space. Next, we need
to change the Hello Universe! text at the top of the screen to be the new screen design’s title,
by editing the hello_world constant in the /values/strings.xml file to hold your new “Galaxy
Information Screen” data value, which we will be using for a title for the new information screen’s
UI design.

Free download pdf