1

因此,当我单击逐项叠加项目时,我只显示一个简单的对话框,我想在下面的行中创建更多内容

点击对话框

我将如何为 android 手机执行此操作>?

4

2 回答 2

3

当您覆盖 ItemizedOverlay 时,有受保护的 onTap 方法。它具有项目索引作为参数。您应该覆盖 onTap 并使用此索引来获取正确的数据对象。例如:

@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 - 您的叠加项目 GeoPoint;popup - 您的自定义对话框视图。

于 2011-06-20T10:20:33.223 回答
1

我刚刚找到了一种方法:扩展 OverlayItem 并覆盖 getMarker 以返回一个新的可绘制对象。

包装 this.is.funny;

导入android.content.Context; 导入android.graphics.Canvas; 导入android.graphics.Color; 导入 android.graphics.ColorFilter; 导入android.graphics.Paint; 导入android.graphics.PixelFormat; 导入android.graphics.Rect; 导入 android.graphics.drawable.Drawable; 导入 android.graphics.drawable.NinePatchDrawable;

导入 com.google.android.maps.GeoPoint; 导入 com.google.android.maps.MapView; 导入 com.google.android.maps.OverlayItem;

公共类 MyOverlayItem 扩展 OverlayItem{ 私有字符串标题; 私有上下文 ctx; 私人 NinePatchDrawable npd; 私有矩形文本框; 私人油漆 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 } }

}

于 2011-06-20T10:06:41.433 回答