Download Teach Yourself Android Application Development in 24

Transcript
152
HOUR 9: Developing the Help and Scores Screens
The scores for the Been There, Done That! application will eventually be sourced
from a remote server, but for now, you can build the screen and use some mock
score data. This mock score data will be provided in XML, so you can mimic the
structure you will use when the real scores are available.
In this instance, you include in the /res/xml/ resource directory two XML files—
allscores.xml and friendscores.xml—that represent the mock score data:
<?xml version=”1.0” encoding=”utf-8”?>
<!— This is a mock score XML chunk —>
<scores>
<score
username=”LED”
score=”12345”
rank=”1” />
<score
username=”SAC”
score=”12344”
rank=”2” />
<score
username=”NAD”
score=”12339”
rank=”3” />
</scores>
The score data uses a very simple schema. A single <scores> element has a number
of child <score> elements. Each <score> element has three attributes: username, score,
and rank. For this example, you can assume that the score data will be sorted and
limited to the top 20 or so scores.
Updating the Scores Screen Layout
The scores screen user interface is defined in the scores.xml layout file. To update
this layout to your intended layout design, you follow these steps:
Watch
Out!
The Eclipse layout resource editor does not display TabHost controls properly in
design mode. To design this kind of layout, you should stick to the XML layout
mode. You must use the Android emulator or an Android device to view the tabs.
1. Remove all the old controls, as you have done for other layouts in this book.
2. Add a new LinearLayout control, setting its android:background attribute to
@drawable/bkgrnd. All subsequent controls will be added inside this
LinearLayout control.
3. Add the same header you created in other layouts. It should contain of a
RelativeLayout control with two ImageView controls and a TextView con-
trol. Set the TextView control’s text attribute to the string resource
@string/scores to reflect the appropriate screen title.