覆盖类应该像下面
public class MapItemOverlay extends ItemizedOverlay<OverlayItem> {
private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
private Context mContext;
private JSONArray marrJson;
private JSONObject mjsonObj;
public MapItemOverlay(Drawable defaultMarker, JSONArray arrJson,
Context context) {
super(boundCenterBottom(defaultMarker));
marrJson = arrJson;
mContext = context;
}
public void addOverlay(OverlayItem overlay) {
mOverlays.add(overlay);
populate();
}
@Override
protected OverlayItem createItem(final int i) {
OverlayItem result = mOverlays.get(i);
LayerDrawable marker = (LayerDrawable) mContext.getResources()
.getDrawable(R.drawable.marker);
GetFBImageTask task = new GetFBImageTask(i, marker, result);
task.execute(new Void[] {});
result.setMarker(boundCenter(marker));
return result;
}
@Override
public int size() {
return mOverlays.size();
}
public MapItemOverlay(Drawable defaultMarker, Context context) {
super(boundCenterBottom(defaultMarker));
mContext = context;
}
@Override
protected boolean onTap(int index) {
return true;
}
public class GetFBImageTask extends AsyncTask<Void, Void, LayerDrawable> {
private LayerDrawable marker;
private OverlayItem result;
private int index;
public GetFBImageTask(int i, LayerDrawable Mmarker, OverlayItem result1) {
marker = Mmarker;
result = result1;
index = i;
}
@Override
protected void onPostExecute(LayerDrawable bmp) {
super.onPostExecute(bmp);
if (bmp != null) {
result.setMarker(boundCenter(bmp));
}
}
@Override
protected LayerDrawable doInBackground(Void... p) {
try {
Bitmap bmp = null;
String[] params = new String[2];
params[0] = "http://your image url";
params[1] = your image name;
URL ulrn = new URL(params[0]);
HttpURLConnection con = (HttpURLConnection) ulrn
.openConnection();
InputStream is = con.getInputStream();
bmp = BitmapFactory.decodeStream(is);
if (null != bmp) {
if (params[1] != null) {
OutputStream fOut = null;
File file = new File(Preference.ImagePath, params[1] + ".jpg");
if (!file.exists()) {
fOut = new FileOutputStream(file);
bmp.compress(Bitmap.CompressFormat.PNG,90, fOut);
fOut.flush();
fOut.close();
}
}
}
if (bmp != null) {
Drawable photo = new BitmapDrawable(
mContext.getResources(), bmp);
marker.setDrawableByLayerId(
R.id.frame,
mContext.getResources().getDrawable(
R.drawable.pa3_map_people_img1));
marker.setDrawableByLayerId(R.id.photo, photo);
marker.setLayerInset(1, 4, 4, 4, 11);
return marker;
}
} catch (Exception e) {
}
return null;
}
}
}
drawble/marker.xml 应该像下面
<item
android:id="@+id/frame"
android:drawable="@drawable/pa3_map_people_img1"/>
<item
android:id="@+id/photo"
android:drawable="@drawable/pa3_map_people_img1"/>