Adding Zoom Controls

For your last exercise in this chapter, you will add two more buttons to your AndroidLBS Activity. These buttons will control the zoom in and zoom out methods of the Google MapView. What makes this modification a little different is that I will introduce a new type of layout for your main.xml file: the RelativeLayout. Whereas LinearLayouts allow you to place Views directly, one after the other, RelativeLayouts let you place Views on top of each other.

For this Activity, you will be placing the two new buttons over the Google Map. To achieve this effect, place the MapView within the RelativeLayout. With the MapView in the RelativeLayout, you can add the buttons that will be placed over the map.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent"

android:layout_height="fill_parent" >

<view class="com.google.android.maps.MapView" android:id="@+id/myMap" android:layout_width="wrap_content" android:layout_height="wrap_content"/> </RelativeLayout>

Now you can add your two additional buttons. Place the buttons so that they appear in the upper-left and lower-left corners of the MapView. You need to make one change to the standard Button layout. By default, the RelativeLayout adds the Button to align with the top edge of the anchor view, in this case, the MapView. Therefore, in the layout, use the android:layout_alignBottom attribute and assign it the id of the MapView. This will align the button to the bottom of the map.

<Button android:id="@+id/buttonZoomIn"

style="?android:attr/buttonStyleSmall" android:text="+"

android:layout_width="wrap_content" android:layout_height="wrap_content" /> <Button android:id="@+id/buttonZoomOut" style="?android:attr/buttonStyleSmall" android:text="-"

android:layout_alignBottom="@+id/myMap" android:layout_width="wrap_content" android:layout_height="wrap_content" />

0 0

Post a comment