Graphics Programs Reference
In-Depth Information
Adding the Fire Button
Now we can continue developing the Tank Fence game. Begin by modifying the
TANK FENCE 3 application from the previous chapter, with output as shown in Fig-
ure 4-53. In Chapter 2 , we worked on the UPDOWN COUNTER application. As in
the UI for that application, we also need up and down buttons for the Tank Fence
game.
For this, simply copy the file updown.xml ( UPDOWN COUNTER/res/layout/
updown.xml ) to the res/layout folder of the TANK FENCE 3 application. You also
need to create the corresponding string and item (id) resources for the buttons.
Note The string resources, such as <string
name="up">UP</string> , are required so that they can be
referenced when setting the labels for the buttons, for example
-
<Button
android:id="@id/up"
an-
droid:text="@string/up" ... /> .
A new id resource (for an element such as button) can be directly
created using the + sign ( @+id ), or it can be created as an item (id)
resource - <item name="up" type="id"/> . Similar to the
way a string resource is referenced ( @string/up ) we can also ref-
erence this id resource when setting the id for an element ( @id/
up ). Although this technique is not very popular, it is very useful to
keep track of the elements (visual and non-visual) used in our ap-
plication.
Both string and id resources have to be placed within the re-
source tag. Commonly, the string resources are added to the res/
values/string(s).xml file, and the id resources are added to
the res/values/id(s).xml file.
After this, we need to add another button to fire missiles. For this, create a new layout
file missile.xml inside the res/layout folder. Add the lines of code from Listing
6-3 to this file.
Listing 6-3. TANK FENCE GAME 1/res/layout/missile.xml
 
 
Search WWH ::




Custom Search