所以当我点击一个逐项的叠加项目时,我只是显示一个简单的对话框,我想在下面的行中创建更多的东西
我如何为Android手机>做这个?
答案 0 :(得分:3)
当您覆盖ItemizedOverlay时,会有受保护的onTap方法。它有项目索引作为参数。您应该覆盖onTap并使用此索引来获取正确的数据对象。 E.g:
@Override
protected boolean onTap(int index) {
getItem(index); \\your overlay item
return true;
}
然后你应该从代码创建自定义对话框或膨胀xml布局,使用正确的布局参数将其添加到MapView上:
MapView.LayoutParams params = new MapView.LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT, point, 0, 0, MapView.LayoutParams.BOTTOM_CENTER);
params.mode = MapView.LayoutParams.MODE_MAP;
MV.addView(popup, params);
MV - 你的MapView实例; point - 你的Overlay项目GeoPoint; 弹出窗口 - 您的自定义对话框视图。
答案 1 :(得分:1)
我刚刚找到了一种方法: 扩展OverlayItem并覆盖getMarker以返回新的drawable。
package this.is.funny;import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.ColorFilter; import android.graphics.Paint; import android.graphics.PixelFormat; import android.graphics.Rect; import android.graphics.drawable.Drawable; import android.graphics.drawable.NinePatchDrawable;
import com.google.android.maps.GeoPoint; import com.google.android.maps.MapView; import com.google.android.maps.OverlayItem;
public class MyOverlayItem extends OverlayItem{ private String title; private Context ctx; private NinePatchDrawable npd; private Rect textBox; private Paint p;
public MyOverlayItem(Context ctx,GeoPoint point, String title, String snippet) { super(point, title, snippet); this.title=title; this.ctx=ctx; p=new Paint(); } @Override public Drawable getMarker(int stateBitset) { return new MyDrawable(); } /** * * I believe this method is the cleaniest way to do what we want. Not sure about it * @author emmanuel * This private class is a custom drawable with some text inside. */ private class MyDrawable extends Drawable{ @Override public void draw(Canvas c) { textBox = new Rect(); //this is ugly p.setFakeBoldText(true); p.setTextSize(16); p.setAlpha(50); p.getTextBounds(title, 0, title.length(), textBox); //p.setAlpha(255); NinePatchDrawable npd; npd=(NinePatchDrawable)
ctx.getResources().getDrawable(R.drawable.geoloc);
npd.setBounds(-(textBox.width()/2+15),-(textBox.height()+30),textBox.width()/2+15,0); npd.draw(c); p.setColor(Color.WHITE); p.setAlpha(255); c.drawText(title,-textBox.width()/2,-30,p); } @Override public int getOpacity() { return PixelFormat.TRANSLUCENT; } @Override public void setAlpha(int alpha) { // TODO Auto-generated method stub } @Override public void setColorFilter(ColorFilter cf) { // TODO Auto-generated method stub } }
}