1. Define the appearance of callout, which can be defined in an XML file.
<? XML version = "1.0" encoding = "UTF-8"?> <Resources> <calloutviewstyle titletextcolor = "#000000" <! -Title color/> titletextsize = 10; <! -Title font size/> titletextstyle = 0; <! -Title Font/> backgroundcolor = "# ffffff" <! -Background color/> backgroundalpha = "255" <! -Transparency 0 (transparent) to 255 (opaque)/> framecolor = "#000000" <! -Border color/> flat = "true" <! -Whether it will be in 3D effect/> cornercurve = "0" <! -Degree of rounded corner/> anchor = "5"/> <! -Position of the anchor (0-8)/> </resources>
2. Define the content to be displayed in callout, which can be defined in a layout.
<? Xmlversion ="1.0"Encoding ="UTF-8"?>
<Linearlayoutxmlns: Android =Http://schemas.android.com/apk/res/android"
Android: layout_width ="Wrap_content"
Android: layout_height ="Wrap_content"
Android: gravity ="Center">
<Imageview
Android: src ="@ Drawable/ic_launcher"
Android: layout_width ="Wrap_content"
Android: layout_height ="Wrap_content"
/>
<TextviewAndroid: text ="This is callout"
Android: layout_width ="Wrap_content"
Android: layout_height ="Wrap_content"/>
</Linearlayout>
3. Display callout. The following code displays callout when you click the screen.
Public
Class Callouttestactivity ExtendsActivityImplementsOnsingletaplistener {
Mapviewmmapview;
PrivateCalloutcallout;
/** Called when the activity is first created .*/
@ Override
Public
VoidOncreate (bundlesavedinstancestate ){
Super. Oncreate (savedinstancestate );
Setcontentview (R. layout.Main);
Mmapview = (mapview) findviewbyid (R. Id.Mapview);
Arcgistiledmapservicelayerarm =NewArcgistiledmapservicelayer ("http://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer ");
Mmapview. addlayer (ARM );
Mmapview. setonsingletaplistener (This);
Callout = mmapview. getcallout (); // obtain the callout of the mapview. One mapview can have only one callout.
}
Public
VoidOnsingletap (FloatArg0,FloatArg1 ){
Pointp = mmapview. tomappoint (NewPoint (arg0, arg1 ));
Callout.Setstyle(R. xml.Colloutxml); // Set the display style (XML defined in step 1)
Callout. setcontent (view.Inflate(This, R. layout.Colloutlay,Null); // Use the layout defined in step 1 as the display content of callout.
Callout. setcoordinates (p); // set the displayed position to the clicked position.
Callout. Show (); // display callout
}
}
4. Effect