I show this link but answer was just only display the开发者_如何学JAVA balloon.
Picture with a border as a map overlay
But I am finding just like the display images with border.... Like this.
If any one have any idea about how to do this so please help me.
I am done display the 3-5 images in map. But now I just want to display that images with border.
Thanks in advance.
you need to create image like this
this is the 9 patch image.
now you need to create the custom layout to handle this the custom layout file for display the balloon
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingBottom="35dip"
android:paddingLeft="10dip"
android:id="@+id/balloon_main_layout"
android:background="@drawable/balloon_overlay_bg_selector"
android:paddingTop="0dip"
android:paddingRight="0dip">
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/your_default_image"
android:id="@+id/img_button"
android:paddingLeft="10dip"
android:paddingBottom="10dip"
android:paddingRight="8dip"
android:paddingTop="8dip"></ImageView>
</LinearLayout>
now you can create this type of image and set as layout background and in that imageview display the different image as per your requirement
here is some code that draws a circle:
private class ProximityOverlay extends Overlay {
public void draw(Canvas canvas, MapView mapview, boolean b) {
// draw some stuff in here, like
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setStrokeWidth(2.0f);
double latitude = location.getLatitude();
double longitude = location.getLongitude();
Projection projection = mapView.getProjection();
GeoPoint leftGeo = new GeoPoint((int) (latitude * 1e6),
(int) (longitude * 1e6));
Point left = new Point();
projection.toPixels(leftGeo, left);
paint.setColor(Color.parseColor("#00CCFF"));
paint.setStyle(Style.FILL);
canvas.drawCircle(left.x, left.y, 9, paint);
paint.setColor(Color.parseColor("#003399"));
paint.setStyle(Style.STROKE);
canvas.drawCircle(left.x, left.y, 10, paint);
}
you can modify it to draw a black rectangle:
canvas.drawRect(left, top, right, bottom, paint);
Create one class BalloonItemizedOverlay as suggested in here
and create xml as you want to display overlay (e.g I have created like this)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingBottom="5dip"
android:paddingLeft="5dip"
android:id="@+id/balloon_main_layout"
android:background="@drawable/popupbg"
android:paddingTop="0dip"
>
<ImageView android:layout_width="40dp"
android:layout_height="40dp"
android:id="@+id/diseaseImg"
android:padding="5dp"
android:layout_gravity="center_vertical"
></ImageView>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1"
android:paddingTop="10dip"
android:paddingRight="30dip"
android:id="@+id/balloon_inner_layout">
<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/balloon_item_title"
android:text="balloon_item_title"
android:layout_marginLeft="2dp"
android:textSize="14dip"
android:paddingBottom="5dp"
android:textColor="#FF000000"></TextView>
</LinearLayout>
<ImageView android:layout_width="30dp"
android:layout_height="30dp"
android:src="@android:drawable/ic_menu_close_clear_cancel"
android:id="@+id/close_img_button"
android:layout_gravity="right"
android:paddingLeft="10dip"
android:paddingBottom="10dip"
android:paddingRight="8dip"
android:paddingTop="2dip"></ImageView>
</LinearLayout>
and also create class BalloonOverlayView like below
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.ImageView.ScaleType;
import com.google.android.maps.OverlayItem;
import com.healthcarealert.R;
public class BalloonOverlayView extends FrameLayout {
private LinearLayout layout;
private TextView title;
private TextView snippet;
private ImageView diseaseImg;
public static boolean isPopupClicked = false;
private Context con = null;
/**
* Create a new BalloonOverlayView.
*
* @param context - The activity context.
* @param balloonBottomOffset - The bottom padding (in pixels) to be applied
* when rendering this view.
*/
public BalloonOverlayView(Context context, int balloonBottomOffset) {
super(context);
this.con =context;
setPadding(10, 0, 10, balloonBottomOffset);
layout = new LinearLayout(context);
layout.setVisibility(VISIBLE);
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = inflater.inflate(R.layout.balloon_map_overlay, layout);
title = (TextView) v.findViewById(R.id.balloon_item_title);
// snippet = (TextView) v.findViewById(R.id.balloon_item_snippet);
diseaseImg = (ImageView)v.findViewById(R.id.diseaseImg);
ImageView close = (ImageView) v.findViewById(R.id.close_img_button);
close.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
layout.setVisibility(GONE);
}
});
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
params.gravity = Gravity.NO_GRAVITY;
addView(layout, params);
}
/**
* Sets the view data from a given overlay item.
*
* @param item - The overlay item containing the relevant view data
* (title and snippet).
*/
public void setData(OverlayItem item) {
layout.setVisibility(VISIBLE);
if (item.getTitle() != null) {
title.setVisibility(VISIBLE);
title.setText(item.getTitle());
} else {
title.setVisibility(GONE);
}
/*if (item.getSnippet() != null) {
snippet.setVisibility(VISIBLE);
snippet.setText(item.getSnippet());
} else {
snippet.setVisibility(GONE);
}*/
}
public void setImage(String item) {
layout.setVisibility(VISIBLE);
if (item != null) {
diseaseImg.setVisibility(VISIBLE);
ImageLoader imageLoader = new ImageLoader(this.con);;
diseaseImg.setTag("http://healthcarealert.com/healthcaretest/" + item);
diseaseImg.setScaleType(ScaleType.FIT_XY);
imageLoader.DisplayImage("http://healthcarealert.com/healthcaretest/" + item,
HotSpotsMapActivity.activity, diseaseImg);
} else {
diseaseImg.setVisibility(GONE);
}
}
}
this class having methode setImage(String item)
Where String contain URL of image
Call this method in onTap methode of HelloItemised overlay with image url path
精彩评论